down the image. This bears repeating:
y-coordinates increase going downward,
which is the opposite of how you may
remember y-coordinates being used in
math class. Figure 17-1 demonstrates how
this coordinate system works.
Many of Pillow’s functions and
methods take a box tuple argument. This
means Pillow is expecting a tuple of four
integer coordinates that represent a rect-
angular region in an image. The four
integers are, in order, as follows:
• Left: The x-coordinate of the leftmost
edge of the box.
• Top: The y-coordinate of the top edge
of the box.
• Right: The x-coordinate of one pixel
to the right of the rightmost edge of
the box. This integer must be greater
than the left integer.
• Bottom: The y-coordinate of one pixel
lower than the bottom edge of the
box. This integer must be greater
than the top integer.
Note that the box includes the left
and top coordinates and goes up to but
does not include the right and bottom
coordinates. For example, the box tuple
(3, 1, 9, 6)
represents all the pixels in
the black box in Figure 17-2.
manipulating images with Pillow
Now that you know how colors and coordinates work in Pillow, let’s use
Pillow to manipulate an image. Figure 17-3 is the image that will be used
for all the interactive shell examples in this chapter. You can download it
Once you have the image ﬁle Zophie.png in your current working direc-
tory, you’ll be ready to load the image of Zophie into Python, like so:
>>> from PIL import Image
>>> catIm = Image.open('zophie.png')
Figure 17-2: The area represented
by the box tuple (3, 1, 9, 6)
Figure 17-1: The x- and y-coordinates
of a 27×26 image of some sort of
ancient data storage device