image reduction script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philippe Martin

    #1

    image reduction script

    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


  • Larry Bates

    #2
    Re: image reduction script

    Philippe Martin wrote:[color=blue]
    > 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
    >
    >[/color]
    Python Imaging Library (PIL).

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

    -Larry Bates

    Comment

    • Philippe Martin

      #3
      Re: image reduction script

      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:
      [color=blue]
      > Philippe Martin wrote:[color=green]
      >> 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
      >>
      >>[/color]
      > Python Imaging Library (PIL).
      >
      > http://www.pythonware.com/products/pil/
      >
      > -Larry Bates[/color]

      Comment

      • Kamilche

        #4
        Re: image reduction script


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

        Comment

        • Philippe Martin

          #5
          Re: image reduction script

          Thanks,

          I'll give it a shot.

          Philippe



          Kamilche wrote:
          [color=blue]
          >
          > To reduce the color depth of an image in PIL:
          > im = im.convert(mode ="P", palette=Image.A DAPTIVE)[/color]

          Comment

          • Philippe Martin

            #6
            Re: image reduction script

            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:
            [color=blue]
            >
            > To reduce the color depth of an image in PIL:
            > im = im.convert(mode ="P", palette=Image.A DAPTIVE)[/color]

            Comment

            • Kamilche

              #7
              Re: image reduction script

              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.

              Comment

              • Philippe Martin

                #8
                Re: image reduction script

                Kamilche wrote:
                [color=blue]
                > 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.[/color]


                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 ***
                ***********conv ert('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:
                ***********conv ert('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



                Comment

                Working...