From PIL import Image
1. Open the picture
img = Image.open (fileName)
2. Save the picture
Img.save (Imgname)
3. Resize the picture
def resize (self, width, height):
O_width, o_height = img.size
O_ratio = O_width/float (o_height)
N_ratio = width/float (height)
If O_ratio > N_ratio:
Re_ration = Width/float (o_width)
a_height = Int (re_ration*o_height)
img = self.img.resize ((width,a_height), Image.antialias)
Else
Re_ration = Height/float (o_height)
a_width = Int (re_ration*o_width)
img = img.resize ((a_width,height), Image.antialias)
Img.save (' test.jpg ')
4. Create a new image
img = image.new ("RGB", (width, height), "black")
5. Paste Copy
box = (+, +, +)#设置要拷贝的区域
Region = im.crop (box)
Region = Region.transpose (image.rotate_180)#从字面上就可以看出, first invert the Image in region by 180 degrees and then back to region.
Im.paste (region, Box)#粘贴box大小的region到原先的图片对象中.
Python python Imaging Library