Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize images in python

Can i resize images in python to given height and width,i use python 2.5, and i tried as this tutorial http://effbot.org/imagingbook/introduction.htm, and i installed PIL library for images,but when i try to write:

import Image
im = Image.open("test.jpg")

i got undefined variable from import:open although import Imagedoesn't give errors? Thanks in advance.

like image 621
Computer_Engineer Avatar asked Jul 21 '26 12:07

Computer_Engineer


2 Answers

Your import appears to be the problem. Use this instead of "import Image":

from PIL import Image

Then go on like so:

image = Image.open('/example/path/to/image/file.jpg/')
image.thumbnail((80, 80), Image.ANTIALIAS)
image.save('/some/path/thumb.jpg', 'JPEG', quality=88)
like image 89
Simon Steinberger Avatar answered Jul 24 '26 01:07

Simon Steinberger


To whom it may be of use: Just found that on the official Pillow website. You probably used Pillow and not PIL.

Warning

Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.

like image 43
Flaudre Avatar answered Jul 24 '26 01:07

Flaudre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!