[Image-SIG] PIL Jpeg resizing in windows
Jim Tittsler
jwt at onjapan.net
Sun Aug 5 11:44:15 CEST 2007
On Jul 30, 2007, at 07:34, Neil Johnson wrote:
> I am new to using PIL and trying to find out how to resize JPEG
> images. I try to resize, and I always get a "pixel access" error
> using the thumbnail, resize, or load functions. Do I need to build
> the PIL from source in order to have JPEG resizing capability?
No.
How large is your source image?
> infile = "image1.JPG"
> PicMaxHeight = 128
Not related to your problem... but you probably will want to do
floating point division.
> im = Image.open(infile)
> im.load()
> file, ext = os.path.splitext(infile)
> ActualSize = im.size
> heightScale = ActualSize[1]/PicMaxHeight
> scaleFactor = heightScale
> newSize = ActualSize[0]/scaleFactor, ActualSize[1]/scaleFactor
>
> ## Now let's try resizing...cross your fingers!
> im.resize(newSize)
Note that the resize() method returns a resized *copy* of the image.
It does not modify the original.
it = im.resize(newSize)
it.save('image1_thumb.jpg')
--
Jim Tittsler http://www.OnJapan.net/ GPG: 0x01159DB6
Python Starship http://Starship.Python.net/crew/jwt/
Mailman IRC irc://irc.freenode.net/#mailman
More information about the Image-SIG
mailing list