Commit 3b29c7e3 authored by fred's avatar fred
Browse files

fix cropping

parent e76b4e5a
......@@ -30,10 +30,7 @@ def thumbnail(image, size='100x100'):
image = Image.open(filename)
if abs( (1.0*x/y) - (1.0*image.size[0]/image.size[1]) ) > 0.1:
# aspect ratio change, crop the image first
if image.size[0] > image.size[1]: # landscape
box = [0, 0, int(image.size[1] * (1.0*y/x)), image.size[1]]
else:
box = [0, 0, image.size[0], int(image.size[0] * (1.0*y/x))]
box = [0, 0, image.size[0], int(image.size[0] * (1.0*y/x))]
if box[2] > image.size[0]:
box = [int(t*(1.0*image.size[0]/box[2])) for t in box]
......@@ -42,8 +39,10 @@ def thumbnail(image, size='100x100'):
if image.size[0] > image.size[1]: # landscape
box[0] = (image.size[0] - box[2]) / 2 # keep the middle
box[2] += box[0]
else:
box[1] = (image.size[1] - box[3]) / 4 # keep mostly the top
box[3] += box[1]
image = image.crop(box)
image = image.resize([x, y], Image.ANTIALIAS)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment