JPG Image Load,Resize,Save with 100% Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ingo Linkweiler

    JPG Image Load,Resize,Save with 100% Python?

    Hello,

    I am looking for a 100% python lib/script which can load a jpg image,
    detect its size, resize and save it as new file.

    I have found some tools (like PIL), but all of them use ImageMagic or
    external dlls, which can not be used on my web server.

    I hope you can help me.

    Ingo

  • Lothar Scholz

    #2
    Re: JPG Image Load,Resize,Sav e with 100% Python?

    Ingo Linkweiler <i.linkweiler@w eb.de> wrote in message news:<c05dj3$q3 7$04$1@news.t-online.com>...[color=blue]
    > Hello,
    >
    > I am looking for a 100% python lib/script which can load a jpg image,
    > detect its size, resize and save it as new file.
    >
    > I have found some tools (like PIL), but all of them use ImageMagic or
    > external dlls, which can not be used on my web server.
    >
    > I hope you can help me.
    >
    > Ingo[/color]

    There is nothing like this.

    Because this is a task that can't be done in Python well.
    You must expect it to be around 140 times (thats 14000%) slower then a
    C library thats why nobody wants to do it.

    Comment

    • Josiah Carlson

      #3
      Re: JPG Image Load,Resize,Sav e with 100% Python?

      > There is nothing like this.[color=blue]
      >
      > Because this is a task that can't be done in Python well.
      > You must expect it to be around 140 times (thats 14000%) slower then a
      > C library thats why nobody wants to do it.[/color]

      140 seems pretty extreme. Most tests I've run put numeric calculations
      at around 10-20 times slower, not 140.

      A better answer as to why there isn't a pure python module is because
      there already exists numerous C JPEG libraries, which are much easier to
      wrap with SWIG, than to rewrite completely in Python.

      - Josiah

      Comment

      • Gilles Lenfant

        #4
        Re: JPG Image Load,Resize,Sav e with 100% Python?

        "Ingo Linkweiler" <i.linkweiler@w eb.de> a écrit dans le message de
        news:c05dj3$q37 $04$1@news.t-online.com...[color=blue]
        > Hello,
        >
        > I am looking for a 100% python lib/script which can load a jpg image,
        > detect its size, resize and save it as new file.
        >
        > I have found some tools (like PIL), but all of them use ImageMagic or
        > external dlls, which can not be used on my web server.
        >
        > I hope you can help me.
        >
        > Ingo
        >[/color]

        Have a look at how Zope detects JPGs and gets their size, in the
        ..../lib/python/OFS/File.py (Image class) in a 100% core Python way.
        Unfortunately resizing a JPEG in pure python is something that nobody does
        because resizing a bitmap image (in whatever format) in pure Python would be
        very slow.

        HTH

        --
        Gilles


        Comment

        • Lothar Scholz

          #5
          Re: JPG Image Load,Resize,Sav e with 100% Python?

          Josiah Carlson <jcarlson@nospa m.uci.edu> wrote in message news:<c06vne$il r$1@news.servic e.uci.edu>...[color=blue][color=green]
          > > There is nothing like this.
          > >
          > > Because this is a task that can't be done in Python well.
          > > You must expect it to be around 140 times (thats 14000%) slower then a
          > > C library thats why nobody wants to do it.[/color]
          >
          > 140 seems pretty extreme. Most tests I've run put numeric calculations
          > at around 10-20 times slower, not 140.[/color]

          A Jpeg libaary with a good optimization does only integer algorithm
          and this is different from FP operations which are already slow on
          Intel CPU's.

          But i find find it strange that numerics (without using special
          extensions) should only be 10-20 times slower then C. This is not what
          you find in other benchmarks.

          For example in the great language shootout
          "http://www.bagley.org/~doug/shootout/bench/sieve/"
          you find that the "Sieve of Eratosthenes" as an integer algorithm 207
          times slower then c. I think the algorithms are compareable in their
          use of instructions.

          Comment

          • Josiah Carlson

            #6
            Re: JPG Image Load,Resize,Sav e with 100% Python?

            >>140 seems pretty extreme. Most tests I've run put numeric calculations[color=blue][color=green]
            >>at around 10-20 times slower, not 140.[/color]
            >
            > A Jpeg libaary with a good optimization does only integer algorithm
            > and this is different from FP operations which are already slow on
            > Intel CPU's.
            >
            > But i find find it strange that numerics (without using special
            > extensions) should only be 10-20 times slower then C. This is not what
            > you find in other benchmarks.[/color]

            That 10-20 times slower metric was doing numerical integration in pure
            Python and ANSI standard C, originally run using Python version 2.0 (2.3
            is roughly 20% faster than 2.0). Certainly it was using floating point
            math, but that suggests that there is less of a difference using Python
            and FP math than when using integer math.

            [color=blue]
            > For example in the great language shootout
            > "http://www.bagley.org/~doug/shootout/bench/sieve/"
            > you find that the "Sieve of Eratosthenes" as an integer algorithm 207
            > times slower then c. I think the algorithms are compareable in their
            > use of instructions.[/color]

            I just sent the author an update to his version in Python that reduces
            runtime from ~47 seconds to ~37 seconds, putting it at only ~160 times
            slower.

            Unfortunately the test still isn't fair. The Python version ends up
            creating and destroying lists (arrays) of 8193 elements, and over the
            running of the algorithm, will need to allocate and free 8 megs. It
            turns out that creating and destroying is faster in Python, but that
            really just means that Python should probably have a better sequence
            initialization function.


            - Josiah

            Comment

            • Derek Ledbetter

              #7
              Re: JPG Image Load,Resize,Sav e with 100% Python?

              On Sun, 8 Feb 2004 5:25:47 -0800, Ingo Linkweiler wrote
              (in message <c05dj3$q37$04$ 1@news.t-online.com>):
              [color=blue]
              > I am looking for a 100% python lib/script which can load a jpg image,
              > detect its size, resize and save it as new file.[/color]

              Note that decoding, resizing and recompressing a JPEG hurts the
              quality. See:


              --
              Derek Ledbetter
              derekl@serve.co m

              Heavy boots of lead
              fills his victims full of dread
              Running as fast as they can
              Iron Man lives again!


              Comment

              • Ingo Linkweiler

                #8
                Re: JPG Image Load,Resize,Sav e with 100% Python?

                > There is nothing like this.[color=blue]
                >
                > Because this is a task that can't be done in Python well.
                > You must expect it to be around 140 times (thats 14000%) slower then a
                > C library thats why nobody wants to do it.[/color]

                thanks, than i will use PIL or wxPython. I have tested both with good
                results.

                Ingo

                Comment

                Working...