[Image-SIG] PIL Jpeg resizing in windows
Neil Johnson
realdealneil at gmail.com
Sun Jul 29 21:34:45 CEST 2007
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? Here is a sample block of code with error
message:
## Try to resize jpegs using PIL:
from PIL import Image
import glob, os
infile = "image1.JPG"
PicMaxHeight = 128
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)
im.save(file + "_thumb", "JPEG")
The error message is:
In [195]: run jpgResize.py
---------------------------------------------------------------------------
exceptions.AttributeError Traceback (most recent
last)
C:\Python24\neil\Directory\jpgResize.py
13
14 ## Now let's try resizing...cross your fingers!
---> 15 im.resize(newSize)
16 im.save(file + "_thumb", "JPEG")
17
C:\Python24\Lib\site-packages\PIL\Image.py in resize(self, size, resample)
1254 raise ValueError("unknown resampling filter")
1255
-> 1256 self.load()
1257
1258 if self.mode in ("1", "P"):
C:\Python24\Lib\site-packages\PIL\ImageFile.py in load(self)
215 self.load_end()
216
--> 217 return Image.Image.load(self)
218
219 def load_prepare(self):
C:\Python24\Lib\site-packages\PIL\Image.py in load(self)
597 self.palette.mode = "RGBA"
598 if self.im:
--> 599 return self.im.pixel_access(self.readonly)
600
601 ##
AttributeError: pixel_access
WARNING: Failure executing file: <jpgResize.py>
Thanks,
Neil Johnson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20070729/cfd2ca34/attachment.html
More information about the Image-SIG
mailing list