Python PIL (Manual: Image module) and pythonpil

Source: Internet
Author: User
Tags glob

Python PIL (Manual: Image module) and pythonpil

Official manual address:Http://effbot.org/imagingbook/image.htm

 

 

Image Module

The image module provides a class with the same name for representing a PIL image. This module also provides many functions, including loading image file functions and creating image functions.

 

Module example:

The following program loads an image, rotates for 45 degrees, and uses an external viewer (typically on Unix, xv [1], on Windows, graph program [2]) display it.

1 # open, rotate, and display an Image (using the default viewer) 2 from PIL import Image3 im = Image. open ("bride.jpg") 4 im. rotate (45). show ()

The following program creates a thumbnail of all JPEG images in the current directory (size: 128x128 ).

1 # create a thumbnail 2 from PIL import Image 3 import glob, OS 4 5 size = 128,128 6 7 for infile in glob. glob ("*. jpg "): 8 file, ext = OS. path. splitext (infile) 9 im = Image. open (infile) 10 im. thumbnail (size, Image. ANTIALIAS) 11 im. save (file + ". thumbnail "," JPEG ")

 

 

 

 

Unfinished, To be continued...

 

Note:

[1] What does xv on Unix mean? It should also be a tool for displaying images. If you know what it means, you can inform me in the comment area and thank you for your feedback.

[2] Run this code on Windows 7 (Virtual Machine). The Windows photo Viewer fails to open the image, prompting that the image does not exist. The third-party Image Viewer Picasa can open the image for unknown reasons.

 

Related Article

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.