I'm attempting to take large (huge) images (from a digital camera), and convert them into something that I can display on the web. This seems straightforward, and probably should be. However, when I attempt to use PIL to create thumbnail versions, if my source image is taller than it is wide, the resulting image is rotated 90 degrees, such that the top of the source image is on the left of the resulting image. If the source image is wider than it is tall, the resulting image is the correct (original) orientation. Could it have to do with the 2-tuple I send in as the size? I'm using thumbnail, because it appears it was meant to preserve the aspect ratio. Or am I just being completely blind, and doing something dumb? The size tuple is 1000,1000 because I want the longest side to be shrunk to 1000 pixels, while keeping AR preserved.
Code seems simple
img = Image.open(filename)
img.thumbnail((1000,1000), Image.ANTIALIAS)
img.save(output_fname, "JPEG")
Thanks in advance for any help.
.thumbnail()
do not rotating – I validated myself usingimg.show()
. It is actually the.save()
method which write to file. What I tried is: – instead of writing to disk-file try writing to in-memory filefrom io import BytesIO; buffer = BytesIO; img.save(buffer, "JPEG"); Image.open(buffer).show()