Speed up convert for padding and resizing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
shayanrc
Posts: 1
Joined: 2015-02-14T01:02:59-07:00
Authentication code: 6789

Speed up convert for padding and resizing

Post by shayanrc »

I'm running the following to first pad an image and then resize it to 64x64:

convert img.jpg -gravity center -background white -extent "$extent_factor"x"$extent_factor" -resize 64x64 img.jpg

Here extent_factor is the height or width of the image (whichever is larger).

Resizing each image takes ~5 seconds this way.

I have close to 35000 images which need to be converted this way. So, it looks like it's going to take close to 48 hrs.

Is there anything I can do to speed it up?

Running "imagemagick -version" gives me:

Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-10-09 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL OpenMP
Delegates: bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma pangocairo png ps rsvg tiff webp wmf x xml zlib

Any help in speeding this up will be appreciated.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Speed up convert for padding and resizing

Post by snibgo »

"-scale" is faster than "-resize", and for such small pictures I doubt you would see the difference.

Changing the size first, then using extent, likewise.

EDIT to add: Q8 may be faster than Q16, but not by much.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Speed up convert for padding and resizing

Post by magick »

Lightning fast:
  • convert -define jpeg:size=64x64 image.jpg -resize 64x64 -background white -extent 64x64 framed.jpg
ImageMagick 6.9.0-4, the current release, has a slight speed optimization which may shave off even more time for this command.
Post Reply