Hi Bharat and people,
I am still watching and following the development of G2, even if I
haven't really contributed much lately, but I think occasionally I
will be able to submit a patch or two.
My question now is about the ImageMagick module. G1 create resizes and
thumbnails with something like:
convert -size 250x250 -geometry 250x250 source.jpg dest.jpg
In G2 this seemed to have changed. Maybe its because Bharat doesn't use
ImageMagick that it hasn't been noticed before, or maybe there is another
explanation.
In a G2-Graphik-Toolkit we have the "scale" (one parameter) and
"resize" (two parameters) operations.
With ImageMagick, 'scale|250' translates into:
convert -scale 250x250 source.jpg dest.jpg
'resize|250|500' translates into:
convert -geometry 250x500 source.jpg dest.jpg
In most (all?) cases 'scale' is used (to generate the thumbnails and
resizes). The problems with this:
* -scale is not available on ImageMagick 4.2.9 (the preferred version by
most people, since its faster, better and generate smaller jpegs than
ImageMagick 5.x.x), so nothing really works when IM4 is installed
* -scale with IM5 is much (> 2x) slower than -size + -geometry
Since I had not much knowledge in ImageMagick before, and since the Typo3
CMS also uses ImageMagick and they recommend IM4, I made some tests to
compare the different releases and the different possibilities to
generate resizes. To compare things, I have timed the equivalent
operations using the netpbm package. Correct me if I did something wrong,
but here's how I create a 250x250 thumbnail from a jpeg:
jpegtopnm -quiet source.jpg | \
pnmscale -xysize 250 250 | \
pnmtojpeg --quality=75 > dest.jpg
Here are the test results and some comments:
Original image size: 1544x1024 685,620 bytes
time file-size ver parameters
00.46s 9,456 bytes IM4 -size 250x250 -geometry 250x250
00.78s 12,013 bytes IM4 -sample 250x250
02.40s 9,709 bytes IM4 -geometry 250x250
00.56s 21,164 bytes IM5 -size 250x250 -geometry 250x250
00.75s 23,897 bytes IM5 -sample 250x250
01.31s 21,136 bytes IM5 -scale 250x250
03.16s 21,417 bytes IM5 -geometry 250x250
03.69s 9,673 bytes Netpbm
The image quality is almost identical on all tests except on -sample,
which is really just to make a very quick resize. The -size along the
-geometry parameter seems to speed up things CONSIDERABLY, on IM4 and
also on IM5. It seems that with -size IM ignores the header information
on the jpeg and treats the file as with 250x250 from the start (but I'm
not sure how...). From the manual:
Use this option to specify the width and height of raw images whose
dimensions are unknown (...) In addition to width and height, use
-size with an offset to skip any header information in the image
Here is another test with a larger image:
Original file: 2272x1704 860,489 bytes
time file-size ver parameters
00.84s 10,656 bytes IM4 -size 250x250 -geometry 250x250
01.69s 11,095 bytes IM4 -sample 250x250
05.54s 9,621 bytes IM4 -geometry 250x250
01.03s 24,982 bytes IM5 -size 250x250 -geometry 250x250
03.06s 25,561 bytes IM5 -sample 250x250
02.70s 23,757 bytes IM5 -scale 250x250
07.53s 23,997 bytes IM5 -geometry 250x250
08.45s 9,779 bytes Netpbm
Well, -size + -geometry is surely the way to go. I have a patch for G2
ready to be submitted which will use this, just wanted to hear about any
mistake I might have made.
--
Ernesto Baschny <ernst@...>
http://www.baschny.de - PGP: http://www.baschny.de/pgp.txt
Sao Paulo/Brasil - Stuttgart/Germany
Ernst@... - ICQ# 2955403
|