0

I have an image that I want to resize - but can tolerate rescaling. The suggestions I have found all maintain the aspect ratio -

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

I've tried thumbnail and resize - but they are maintain aspect. How can I resize/rescale without maintaining aspect?

Community
  • 1
  • 1
farrellmr
  • 1,815
  • 2
  • 15
  • 26

1 Answers1

0
  • .thumbnail preserves the aspect ratio and modifies the image inplace.
  • .resize does not preserve aspect ratio, and returns a new image.

im = Image.open(infile)
im = im.resize(size, Image.ANTIALIAS)
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677