To create thumbnails of image files we can use few libraries like:
But there are also smaller libraries like Epeg from the development branch of Enlightment (E17) which uses only libjpeg to make thumbnails. Now which of them will be faster? And if we make Python modules from EPEG library how much slower they will be than the original C runtime?
We can download EPEG source code and compile it without e17 (needs only libjpeg). After compile and install there will be an app called "epeg", but we will make our own, with epeg.c file like this:
To compile it use:
gcc epeg.c -o epeg `epeg-config --cflags --libs`
And the compile "epeg" binary can be used like this:
./epeg -i file.jpg -o thumb.jpg -h heigth -w width -q quality
Python Imaging Library - the thing you would use in Python to make thumbs. It also has some filters like ANTIALIAS and SHARPEN which increase the quality of the thumbnails. Test script looks like this:
We can use Python standard API in C to make a Python module. The code would look like this:
And compiled with (-fPIC needed on 64 bit Linux):
- I've measured time (bash/time) needed to make thumbs from 18 big JPEG files (35 MB).
- For every tested library a simple bash script was used. For imagemagick:
- EDIT: in case of imagemagick also -size param should be set so imagemagick would only read needed part of file to create the thumb, and not the whole.
- All libraries were ordered to make the same thumbs with the same settings (quality, width, heigth).
gcc -shared -I /usr/include/python2.5/ epg.c -o epg.so -fPIC `epeg-config --cflags --libs`
We can also use C++ and BOOST/Python. The code would look like this:
Compiled with (-fPIC needed on 64 bit Linux):
gcc -lboost_python -shared -I /usr/include/python2.5/ bstepg.cpp -o bstepg.so -fPIC `epeg-config --cflags --libs` -I/usr/include/boost
If we use a Python module of a C "application" we loose here about 10% of it's speed, which isn't much compared to PIL, or IMAGEMAGICK "convert". In case of EPEG there is a problem with no anti-alias filters, and without that (and sharpen) some thumbnails will be fuzzy and unacceptable :)
- EPEG - 4,15s
- PyEPEG C - 4,54s
- PyEPEG BOOST - 4,58s
- PIL - 11,61s
- IMAGEMAGICK - 29,32s
- IMAGEMAGICK -size - 10,9s (edit/update)
1,3 MB, 2560x1600
27 kB, 300x506