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

  • Thread starter Ingo Linkweiler
  • Start date
I

Ingo Linkweiler

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
 
L

Lothar Scholz

Ingo Linkweiler said:
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

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.
 
J

Josiah Carlson

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.

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
 
G

Gilles Lenfant

Ingo Linkweiler said:
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

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
 
L

Lothar Scholz

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

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.
 
J

Josiah Carlson

140 seems pretty extreme. Most tests I've run put numeric calculations
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.

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.

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.

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
 
D

Derek Ledbetter

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.

Note that decoding, resizing and recompressing a JPEG hurts the
quality. See:
http://www.faqs.org/faqs/jpeg-faq/

--
Derek Ledbetter
(e-mail address removed)

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

Ingo Linkweiler

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.

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

Ingo
 

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
474,178
Messages
2,570,955
Members
47,509
Latest member
Jack116

Latest Threads

Top