Image
Pillow library Image provides support for creating and manipulating images.
Standard package
Modules using `Image
typically include the following import
from PIL import Image
Functions
Image.open( n )
: returns anImage
representation of the image file named byn
. Parametern
is the name of a local file.
Image.new( m, size, color='black' )
returns a modem
new image, whose dimensions aresize
. The background of the imagecolor
. Parametercolor
is optional with a default value of black.
- The mode is the representation to be used for the pixels in the image. Typically, we will use an RGB ('RGB') pixel color representation. Other common representations are RGBA, HSV, CMYK, I and F.
- An image size is specified as a two-tuple
(w, h)
wherew
andh
are respctively the desired width and height. A two-tuple is often referred to as an ordered-pair.
Image members
Suppose below im
is an Image
object, spot
is a two-tuple (x, y)
representing an image coordinate of interest, and c
is a pixel (color).
Fields
im.width
is the width of of imageim
.
im.height
is the height of of imageim
.
im.size
is a two-tuple giving the width and height of imageim
.
For example, the first two statements in following code segment initialize respectively
w
andh
to the width and height of imageim
. The third statement initializes respectivelysw
andsh
also to the width and height of imageim
.
w = im.width
h = im.height
sw, sh = im.size
Methods
im.getpixel( spot )
: returns the value of the pixel at coordinatespot
in imageim
.
im.putpixel( spot, c )
: sets the pixel at coordinatespot
in imageim
toc
.
im.copy( )
: returns a newImage
copy ofim
.
im.show( )
: popups a copy ofim
.
im.save( n, format=None )
: saves imageim
to local filen
where the picture file type is specified byNone
. If theformat
parameter is omitted orNone
, the file type is given the filename extension ofn
.