PIL & image size reduction script

nikie n.estner at gmx.de
Sun Mar 26 19:36:20 EST 2006


Philippe Martin wrote:
> Hi,
>
> 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?

> 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) 

Hope this helps.

Niki




More information about the Python-list mailing list