in reply to advice on OO and perlmagick
Notice in this first example, that undef @$image is needed to clear out the image stack. I guess this is a common way of storing data in objects, see "perldoc -q clear", for "how do I clear a package".
Now in this second example, I don't clear out the data, and tell the IM object to Read multiple files. When I tell the IM object to Write, it will loop thru all it's Read images and write them out, with separate names. I'm sure what montage does, it writes all those images out, put to a single file, NOT multiple files.#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image = Image::Magick->new; umask 0022; my @pics= <*.png>; foreach my $pic (@pics){ my ($picbasename) = $pic =~ /^(.*).png$/; my $ok; $ok = $image->Read($pic) and warn ($ok); my $thumb = $picbasename . '-t.png'; $image->Scale(geometry => '100x100'); $ok = $image->Write($thumb) and warn ($ok); undef @$image; #needed if $image is created outside loop print "$pic -> $thumb\n"; }
So here is the second example modified to make a montage, you will see all the files in a single file, instead of auto-named separate files.#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image = Image::Magick->new; umask 0022; my @pics= <*.png>; my $ok; foreach (@pics){ $ok = $image->Read($_) and warn ($ok); } $image->Scale(geometry => '100x100'); $ok = $image->Write('thumb.png') and warn ($ok);
So all you need to realize, is that to reuse an IM object, just undef @$images.#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image = Image::Magick->new; umask 0022; my @pics= <*.png>; my $ok; foreach (@pics){ $ok = $image->Read($_) and warn ($ok); } my $montage = $image->Montage(geometry=>'128x160+8+4>',gravity=>'Cente +r', tile=>'6x+10+200',compose=>'over',background=>'#ffffff', font=>'Generic.ttf',pointsize=>18,fill=>'#600',stroke=>'none'); $ok = $montage->Write('montage.png') and warn ($ok);
The IM documentation, is particularly confusing and incomplete, sometimes you need to search groups.google.com for examples of syntax, and sometimes you just need to make educated guesses to convert commandline syntax to Perl syntax. The way to get a warning out of an IM object method, is confusing too, I remember getting that tip from merlyn
|
|---|