Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple thumbnails in ImageMagick / GraphicsMagick

I'm currently writing a shellscript for Bash, that will create different size thumbnails for some rather massive amounts of large images.

I was wondering if it's possible to get GM/IM to create multiple sizes of thumbs in one run, to avoid loading the same image over and over again to create different thumbnails, thus saving memory and time in executing the script ?

like image 515
Jesper Rasmussen Avatar asked Mar 25 '11 10:03

Jesper Rasmussen


2 Answers

According to this post you can use -write filename with GraphicsMagick to "write the current image to the specified filename and then continue processing ... to produce the various smaller sizes while reading the original image just once".

like image 60
Isius Avatar answered Nov 19 '22 07:11

Isius


You can do it with the ImageMagick Perl bindings, or bindings into any other language of your choice:

#!/usr/bin/perl
use Image::Magick;

my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('sars.png');
warn "$x" if "$x";

$x = $image->Resize(geometry=>'600x600');
warn "$x" if "$x";

$x = $image->Write('x.png');
warn "$x" if "$x";

$x = $image->Resize(geometry=>'400x400');
warn "$x" if "$x";

$x = $image->Write('y.png');
warn "$x" if "$x";

$x = $image->Resize(geometry=>'100x100');
warn "$x" if "$x";

$x = $image->Write('z.png');
warn "$x" if "$x";

The conjure command supports an XML-formatted Magick Scripting Language, but it's harder on my eyes than the Perl version, and the documentation on the Perl bindings is definitely better.

like image 1
sarnold Avatar answered Nov 19 '22 08:11

sarnold