python - How to force Pillow to resize an image to an arbitrary size? -
i need resize images, different sizes 144x144.
all sizes: 968x565, 25x48, 400x400, etc. don't know input. i'm using pillow library python. don't mind losing aspect ratio.
problem is: when using resize
method, images complete random sizes. not always, of them don't respect arbitrary size of 144x144 gave method. here sample.
i tried resizing these images using mac os x yosemite's preview , works flawlessly. need in pillow force 144x144 size , work @ least preview in mac?
i can't post whole code, snippet resizes is:
#!/usr/bin/env python # -*- coding: utf-8 -*- pil import image im = image.open('canvas_wheat.jpg') im.resize((144, 144), image.antialias) im.save('144.jpg', optimize=true, quality=20)
the problem getting there resize
method returns new image object, not storing anywhere. original image im
same has been loaded.
check examples on interactive session:
>>> pil import image >>> img = image.open("image.jpg") >>> img.size (952, 804) >>> img2 = img.resize((144,144), image.antialias) >>> img.size (952, 804) >>> img2.size (144, 144) >>>
Comments
Post a Comment