Python python Imaging Library

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.