I’m trying to crop a picture to 1000 by 1000 pixels. It works to crop the far left of the picture.
JavaScript
x
17
17
1
img = Image.open('image.jpg')
2
(width, height) = img.size
3
if width >= height:
4
multiplier = 1000 / height
5
height = int(height * multiplier + 1)
6
width = int(width * multiplier + 1)
7
img = img.resize((width, height))
8
cropped_img = img.crop((0,0, 1000,1000))
9
cropped_img.save("background_image.png")
10
if height >= width:
11
multiplier = 1000 / width
12
width = int(width * multiplier + 1)
13
height = int(height * multiplier + 1)
14
img = img.resize((height, width))
15
cropped_img = img.crop((0,0, 1000,1000))
16
cropped_img.save("background_image.png")
17
However, if I attempt to change the crop to the far right it returns an error:
SystemError: tile cannot extend outside image
JavaScript
1
17
17
1
img = Image.open('image.jpg')
2
(width, height) = img.size
3
if width >= height:
4
multiplier = 1000 / height
5
height = int(height * multiplier + 1)
6
width = int(width * multiplier + 1)
7
img = img.resize((width, height))
8
cropped_img = img.crop((1000,1000, 0, 0))
9
cropped_img.save("background_image.png")
10
if height >= width:
11
multiplier = 1000 / width
12
width = int(width * multiplier + 1)
13
height = int(height * multiplier + 1)
14
img = img.resize((height, width))
15
cropped_img = img.crop((1000,1000, 0, 0))
16
cropped_img.save("background_image.png")
17
Advertisement
Answer
As the comments and the documentation pointed out, parameters should be supplied in the form of (left, upper, right, lower)
.
In your case, this translates to (width - 1000, height - 1000, width, height)