image reduction script

Discussion in 'Python' started by Philippe Martin, Mar 24, 2006.

  1. 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
     
    Philippe Martin, Mar 24, 2006
    #1
    1. Advertising

  2. Philippe Martin

    Larry Bates Guest

    Philippe Martin wrote:
    > 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
     
    Larry Bates, Mar 24, 2006
    #2
    1. Advertising

  3. Larry,

    I actually did not find what I needed in PIL (missed it ?) but found this
    package quite usefull: http://www.imagemagick.org/script/index.php

    Philippe





    Larry Bates wrote:

    > Philippe Martin wrote:
    >> 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
     
    Philippe Martin, Mar 25, 2006
    #3
  4. Philippe Martin

    Kamilche Guest

    To reduce the color depth of an image in PIL:
    im = im.convert(mode="P", palette=Image.ADAPTIVE)
     
    Kamilche, Mar 26, 2006
    #4
  5. Thanks,

    I'll give it a shot.

    Philippe



    Kamilche wrote:

    >
    > To reduce the color depth of an image in PIL:
    > im = im.convert(mode="P", palette=Image.ADAPTIVE)
     
    Philippe Martin, Mar 26, 2006
    #5
  6. 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




    Kamilche wrote:

    >
    > To reduce the color depth of an image in PIL:
    > im = im.convert(mode="P", palette=Image.ADAPTIVE)
     
    Philippe Martin, Mar 26, 2006
    #6
  7. Philippe Martin

    Kamilche Guest

    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.
     
    Kamilche, Mar 26, 2006
    #7
  8. Kamilche wrote:

    > 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
     
    Philippe Martin, Mar 26, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick

    Bus reduction

    Patrick, Jun 7, 2004, in forum: VHDL
    Replies:
    1
    Views:
    568
    Egbert Molenkamp
    Jun 7, 2004
  2. Bryan Galvin

    NodeSet Reduction

    Bryan Galvin, Jun 9, 2004, in forum: XML
    Replies:
    3
    Views:
    436
    Bryan Galvin
    Jun 14, 2004
  3. Bryan Galvin
    Replies:
    2
    Views:
    436
    Bryan Galvin
    Sep 29, 2004
  4. A B Carter

    efficient list reduction

    A B Carter, May 11, 2004, in forum: Python
    Replies:
    2
    Views:
    561
    Paul Rubin
    May 11, 2004
  5. Philippe Martin

    PIL & image size reduction script

    Philippe Martin, Mar 26, 2006, in forum: Python
    Replies:
    5
    Views:
    383
    Philippe Martin
    Mar 27, 2006
Loading...

Share This Page