By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,715 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Ingo Linkweiler <i.**********@web.de> wrote in message news:<c0*************@news.t-online.com>...
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.
Jul 18 '05 #2

P: n/a
> 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
Jul 18 '05 #3

P: n/a
"Ingo Linkweiler" <i.**********@web.de> a écrit dans le message de
news:c0*************@news.t-online.com...
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

--
Gilles
Jul 18 '05 #4

P: n/a
Josiah Carlson <jc******@nospam.uci.edu> wrote in message news:<c0**********@news.service.uci.edu>...
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 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.
Jul 18 '05 #5

P: n/a
>>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.


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

Jul 18 '05 #6

P: n/a
On Sun, 8 Feb 2004 5:25:47 -0800, Ingo Linkweiler wrote
(in message <c0*************@news.t-online.com>):
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
de****@serve.com

Heavy boots of lead
fills his victims full of dread
Running as fast as they can
Iron Man lives again!
Jul 18 '05 #7

P: n/a
> 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

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.