我正在尝试裁剪图像,然后将裁剪后的图像粘贴到另一个图像的中心.理想情况下,我希望裁剪的图像比粘贴的图像小,以便在粘贴的图像周围有边框,但我不知道是否可能.
这是我尝试过的(以及产生的错误消息):
>>> import Image
>>> grey = Image.new('RGB', (200, 200), "grey")
>>> House = Image.open("House01.jpg")
>>> print grey.size, grey.mode, grey.format
>>>(200, 200) RGB None
>>> print House.size, House.mode, House.format
>>>(300, 300) RGB JPEG
>>> box = (25, 25, 25, 25)
>>> House.crop(box)
>>>Image._ImageCrop image mode=RGB size=0x0 at 0x11AD210>
>>> region = House.crop(box)
>>> region.show()
>>>Traceback (most recent call last):
>>> File "<pyshell#28>", line 1, in <module>
region.show()
>>> File "C:\Python26\lib\site-packages\PIL\Image.py", line 1483, in show
_show(self, title=title, command=command)
>>> File …Run Code Online (Sandbox Code Playgroud)