PIL & image size reduction script
pmartin at snakecard.com
Mon Mar 27 14:42:30 CEST 2006
> Philippe Martin wrote:
>> Thanks to the NG, I got the script hereunder working.
>> 1) I am not certain that the call to convert does much (checking the doc)
> I think you only need it if your source image comes in a format that
> can't be stored into a jpeg file (e.g. 8-bit paletted). You'll need
> that if you're converting from GIF files, for example. It shouldn't
> hurt otherwise.
>> 2) Can this be improved as far as the final image size in (X,Y) ?
> I'm not sure if I get you: You tell the image object it's new
> (X,Y)-size in the resize method, don't you?
Yes, I keep reducing the (X,Y) size as long as the file is too large (in
>> For instance, passing a large .jpg with a target byte size of 7000, I get
>> final (X,Y) results around (213, 174) ... but might want to strech it a
>> bit while keeping the byte size.
> If I got you right, you want to compress the image to a certain file
> size. Maybe you should try optimizing the additional save parameters
> for the jpeg encoder.
> (http://www.pythonware.com/library/pil/handbook/formats.htm). Try
> reducing the "quality" parameter.
> l_image.save(l_tmp_file_name, quality=25)
That might be it !!!
> Hope this helps.
More information about the Python-list