You want to resize the thumbnail while maintaining the original proportion in the plot.
How can I change the size of the thumbnail in PIL?
image python pil python-imaging-libaray thumbnail
If it's a thumbnail, I guess it's to reduce the size.
Set the maximum size and obtain the ratio with ratio = min(maxwidth/width, maxheight/height)
.
Or you can use Image.thumbnail(size, resample=3) provided by PIL.
(size
) Create a thumbnail below.)
Please refer to the example in the tutorial
import os, sys
import Image
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for '%s'" % infile
© 2024 OneMinuteCode. All rights reserved.