Scaling pictures

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kajsa Anka

    #1

    Scaling pictures

    I would like some advice, I'm going to build a small app that will, among
    other things, scale images so that they can be published on a web site. I've
    never done any image processing in python before so I would like to ask what
    is the best way of doing this, I will not do anything else than scaling the
    images.

    I found the Python Imaging Library but before I dive into that I would like
    to know if there is a better way of doing this.

  • buffi

    #2
    Re: Scaling pictures

    Kajsa Anka wrote:
    I would like some advice, I'm going to build a small app that will, among
    other things, scale images so that they can be published on a web site. I've
    never done any image processing in python before so I would like to ask what
    is the best way of doing this, I will not do anything else than scaling the
    images.
    >
    I found the Python Imaging Library but before I dive into that I would like
    to know if there is a better way of doing this.
    I prefer using imagemagick whenever I have to do anything related to
    images.


    Resizing an image would be something like this

    import os

    filename = "picture.pn g"
    outputfile = "picture_resize d.png"
    new_size = "100x100"
    os.system("conv ert %s -resize %s %s" % (filename, new_size, outputfile))

    Comment

    • Ravi Teja

      #3
      Re: Scaling pictures


      Kajsa Anka wrote:
      I would like some advice, I'm going to build a small app that will, among
      other things, scale images so that they can be published on a web site. I've
      never done any image processing in python before so I would like to ask what
      is the best way of doing this, I will not do anything else than scaling the
      images.
      >
      I found the Python Imaging Library but before I dive into that I would like
      to know if there is a better way of doing this.
      Yes. Python Imaging Library (PIL) is the preferred Python way to do
      this. The example is right in the documentation.
      http://www.pythonware.com/library/pi...book/image.htm

      from PIL import Image
      import glob, os

      size = 128, 128

      for infile in glob.glob("*.jp g"):
      file, ext = os.path.splitex t(infile)
      im = Image.open(infi le)
      im.thumbnail(si ze, Image.ANTIALIAS )
      im.save(file + ".thumbnail ", "JPEG")

      Comment

      • bearophileHUGS@lycos.com

        #4
        Re: Scaling pictures

        Kajsa Anka:
        I found the Python Imaging Library but before I dive into that I would like
        to know if there is a better way of doing this.
        PIL is very fit for that. Note that it creates thumbnails already by
        itself, you can use that for bigger images too.

        Bye,
        bearophile

        Comment

        • Kajsa Anka

          #5
          Re: Scaling pictures

          On Thu, 28 Dec 2006 11:53:41 +0100, Kajsa Anka wrote
          (in article <0001HW.C1B960C 5006E7E2DF04886 48@News.Individ ual.DE>):

          Thanks for the answers, I'll use PIL.

          jem

          Comment

          • cyberco

            #6
            Re: Scaling pictures

            PIL is certainly a fine option, but I noticed that the scaled images
            (scaled with the ANTIALIAS filter) are not as good as you can get with,
            say, Photoshop. Maybe I'm just expecting too much, but I wish I could
            choose a higher quality rescaling algorithm. PIL still rocks though.

            On Dec 28, 2:32 pm, "Ravi Teja" <webravit...@gm ail.comwrote:
            Kajsa Anka wrote:
            I would like some advice, I'm going to build a small app that will, among
            other things, scale images so that they can be published on a web site. I've
            never done any image processing in python before so I would like to ask what
            is the best way of doing this, I will not do anything else than scaling the
            images.
            >
            I found the Python Imaging Library but before I dive into that I would like
            to know if there is a better way of doing this.Yes. Python Imaging Library (PIL) is the preferred Python way to do
            this. The example is right in the documentation.http://www.pythonware.com/library/pi...book/image.htm
            >
            from PIL import Image
            import glob, os
            >
            size = 128, 128
            >
            for infile in glob.glob("*.jp g"):
            file, ext = os.path.splitex t(infile)
            im = Image.open(infi le)
            im.thumbnail(si ze, Image.ANTIALIAS )
            im.save(file + ".thumbnail ", "JPEG")

            Comment

            • cyberco

              #7
              Re: Scaling pictures

              cyberco wrote:
              PIL is certainly a fine option, but I noticed that the scaled images
              (scaled with the ANTIALIAS filter) are not as good as you can get with,
              say, Photoshop. Maybe I'm just expecting too much, but I wish I could
              choose a higher quality rescaling algorithm. PIL still rocks though.
              Sorry, I should have checked the facts a little better: you can set the
              quality of the compression when saving:

              =============== =============== ======
              img = Image.open('old .jpg')
              img.thumbnail(( 640,480), Image.ANTIALIAS )
              img.save('new.j pg', quality=95)
              =============== =============== ======

              Now PIL is definitely the way to go. :)

              Comment

              Working...