faster jpeg resizing with imagemagick

Replies:

Parents:

  • None.
I found a page with misc imagemagick tips [1], and this one on
faster jpeg resizing looks really useful:

> The -size option tells the IM jpeg decoder that the image being read
> will be resized later.  This lets it run faster  by avoiding returning
> full-resolution images, for later resizing.

   gerald@devo:/tmp; time convert -resize 256x192 a.jpg a-sm.jpg
   real    0m16.737s
   user    0m10.460s
   sys     0m0.250s

   gerald@devo:/tmp; time convert -size 512x384 -resize 256x192 a.jpg a-sm.jpg
   real    0m2.487s
   user    0m1.490s
   sys     0m0.060s

(a.jpg is a 2048x1536 photo, 1745586 bytes. The times above are
extra slow because both CPUs are also busy doing wavs->oggs :)

Does anyone know if doing this is a bad idea for some reason?

I'd like to use this when generating thumbnails and other smaller
versions of photos; I don't see any difference at e.g. 400x300.

That part of my photo publishing process is really time consuming
(well, just for the machine, but I have to wait around for it);
would be nice to speed it up by a factor of 5+ :)

I wonder what the difference is between -resize and -geometry; I
have always used -geometry.

the whole tip:
> Faster JPEG resizing
>
> The -size option tells the IM jpeg decoder that the image being read
> will be resized later.  This lets it run faster  by avoiding returning
> full-resolution images, for later resizing.
>
> For example...
>    convert -size 120x120 cockatoo.jpg -resize 120x120 \
>           +profile "*" cockatoo_thumb.gif
>
> This may not give as nice as a result as just the -resize filter itself, but
> it is a lot faster. If you like you could also use -size to scale part way and
> -resize to finalize.  For example if you are starting with a 3000x2000 jpeg
> and want a 120x80 thumbnail, you could use "-size 480x320" then "-resize
> 120x80"
>
> NOTE: -resize uses the filter selected with -filter while -scale uses a
> simple fast scaling method.  -resize & -filter give you more control
> but might consume more CPU time.

[1] http://www.sct.gu.edu.au/~anthony/info/graphics/imagemagick.hints

--
Gerald Oskoboiny <[email protected]>
http://impressive.net/people/gerald/

Re: faster jpeg resizing with imagemagick

Replies:

  • None.

Parents:

On Friday 13 June 2003 18:26, Gerald Oskoboiny wrote:
> Does anyone know if doing this is a bad idea for some reason?

I've never noticed a problem when I did this for my thumbnails. However, I
noted I didn't use it for the "web sized" photos and your email prompted me
to go back and re-investiage for those larger images: it significantly
speeds it up, and I don't notice any image degredation.

> That part of my photo publishing process is really time consuming
> (well, just for the machine, but I have to wait around for it);
> would be nice to speed it up by a factor of 5+ :)

Indeed! Presently my script (below) is really stupid, but it works. If I
start doing this trick for the "web" photos too, that speeds a "web folder
gallery" generation for this month from 2m44s to 1m28s. Also, it'd be cool
if I detected whether an image has changed and consequently requires
regeneration...

> I wonder what the difference is between -resize and -geometry; I
> have always used -geometry.

This stuff always confused me terribly. I used to use geometry, but in some
ImageMagick release I believe I read that I should be using "size" for what
I was doing.

----------

#!/bin/bash

if [ ! -d ./images ]; then mkdir ./images; fi;
if [ ! -d ./images/thumbs ]; then mkdir ./images/thumbs; fi;

if [ -f .htaccess ]; then
   cp .htaccess images/;
   echo -e "<Files "*.jpg">\nAllow from all\n</Files>" >
images/thumbs/.htaccess
   fi;


for f in *.jpg;
do
  convert -size "700x700" -resize "600x600>" -quality 60 \
  -border 4x6 -bordercolor black \
  -comment "%c Copyright 2003 http://goatee.net/" -antialias -pointsize 12\
  -font 'helvetica' \
  -fill '#999999' -gravity SouthEast \
  -draw 'text 10,20 "� 2003 http://goatee.net/"' \
  $f ./images/$f
  convert -size "160x120" -quality 60  -resize "160x120"  $f
./images/thumbs/$f;
done

webdir=`pwd | sed -e 's/hires/web/' -e s/images//`
# cp -r images/thumbs/* $webdir/thumbs/   # uncomment (and comment others)
for icons only
rm -rf $webdir
if [ ! -d $webdir ]; then mkdir $webdir; fi;
cd images;
if [ -f .htaccess ]; then cp .htaccess $webdir; fi;
cp -r * $webdir
pushd $webdir; igal > index.html; popd;
cd ..; rm -rf images

HURL: fogo mailing list archives, maintained by Gerald Oskoboiny