How to I use Python PIL to produce a 1000x1000 thumbnail without distorting the image
Solution 1:
From what I understand from your question, whatever be the size of the image, it needs to be cropped to a 1000x1000 image.
One way to do this is by first cropping the image into a square and then resizing it to 1000x1000.
(width, height) = img.size
if width < height: # if width is smaller than height, crop height
h = int((height - width)/2)
new_img = img.crop((0, h, width, width+h))
else: # if height is smaller than width, crop width
w = int((width - height)/2)
new_img = img.crop((w, 0, height+w, height))
# resize to required size
new_img = new_img.resize((1000,1000))
It is more efficient to crop first and then enlarge than to enlarge first and then crop. This is because in the second case, you are doing image operations (i.e, cropping) on a larger image which uses more resources (CPU, RAM, etc) than cropping smaller images. If you're working on large number of images this could result considerable difference in processing time.