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.