There is a crop() method:
w, h = yourImage.size
yourImage.crop((0, 30, w, h-30)).save(...)
Answer from ninjagecko on Stack OverflowVideos
This doesn't really make a lot of sense to me but my cropping doesn't work unless I .show() the crop.
crop = image.crop((968, 508, 1050, 532)) crop.show() # <- this is the issue temp = Image.new(mode='RGBA', size = crop.size, color=(255,255,255,0)) image.paste(temp, (968, 508, 1050, 532)) #Sets cropped area to white image.paste(crop, (1017, 508, 1099, 532)) #Replaces cropped area, shifted
So this crops a section of my picture, turns it all white, then places the cropped part back, just shifted a bit to the right. However, if I remove the crop.show() line then it doesn't work. Here are the images, the change is to the left of "Passing"
One
Two
Any help to this confusing issue is appreciated.
There is a crop() method:
w, h = yourImage.size
yourImage.crop((0, 30, w, h-30)).save(...)
(left, upper, right, lower) means two points,
- (left, upper)
- (right, lower)
with an 800x600 pixel image, the image's left upper point is (0, 0), the right lower point is (800, 600).
So, for cutting the image half:
from PIL import Image
img = Image.open("ImageName.jpg")
img_left_area = (0, 0, 400, 600)
img_right_area = (400, 0, 800, 600)
img_left = img.crop(img_left_area)
img_right = img.crop(img_right_area)
img_left.show()
img_right.show()

Coordinate System
The Python Imaging Library uses a Cartesian pixel coordinate system, with (0,0) in the upper left corner. Note that the coordinates refer to the implied pixel corners; the centre of a pixel addressed as (0, 0) actually lies at (0.5, 0.5).
Coordinates are usually passed to the library as 2-tuples (x, y). Rectangles are represented as 4-tuples, with the upper left corner given first. For example, a rectangle covering all of an 800x600 pixel image is written as (0, 0, 800, 600).