image reduction script

P

Philippe Martin

Hi,

I need to write a script to reduce the resolution/color depth of an image
(ex: .jpg) based on a target size.

The point is for the target picture to still be "understandable" - yet I
target getting down to 5K.

Are there libraries out there that could help me start ?

Thanks

Philippe
 
L

Larry Bates

Philippe said:
Hi,

I need to write a script to reduce the resolution/color depth of an image
(ex: .jpg) based on a target size.

The point is for the target picture to still be "understandable" - yet I
target getting down to 5K.

Are there libraries out there that could help me start ?

Thanks

Philippe
Python Imaging Library (PIL).

http://www.pythonware.com/products/pil/

-Larry Bates
 
K

Kamilche

To reduce the color depth of an image in PIL:
im = im.convert(mode="P", palette=Image.ADAPTIVE)
 
P

Philippe Martin

Kamilche,

I am posting the code in another thread but am not certain that convert does
anything to the picture color depth ... still searching in the doc.

Philippe
 
K

Kamilche

Be sure and use mode = P instead of RGB, like you have in your other
code. P is for palettized images. Don't palettize if you're storing as
JPG, only if you're storing as PNG or some other format that can handle
256 color images.
 
P

Philippe Martin

Kamilche said:
Be sure and use mode = P instead of RGB, like you have in your other
code. P is for palettized images. Don't palettize if you're storing as
JPG, only if you're storing as PNG or some other format that can handle
256 color images.


My problem is this:

1) If I use a save to jpg after a convert('P') I get an exception (what you
are refering to I assume)
2) If I use a save to png (I start with a jpg), then the (X,Y) size of the
output is much smaller than convert('RGB') and save to jpg - (and I want to
opposit: as small as possible in byte size and as large as possible in
(X,Y) ):

*** SAME INPUT FILE.JPG ***
***********convert('P') save to PNG
/home/philippe/tmp/tmprpdfEO is a 65x87 Raw PPM image with 256 levels
Default gamma for ITRUE image is 1.00
Building XImage...done
Have adjusted image from 1.00 to display gamma of 2.20

Versus:
***********convert('RGB') save to JPG
/home/philippe/tmp/tmpYCLrQR is a 173x231 Raw PPM image with 256 levels
Default gamma for ITRUE image is 1.00
Building XImage...done
Have adjusted image from 1.00 to display gamma of 2.20


Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top