I stumbled upon IM's way of storing multiple images myself, within a single IM object. They get pushed into an array, and when you tell IM to write, it will do all the images it has pushed into it. The only example I have, is a thumbnail creation script, which I have modified to exagerate the IM object's way of processing everything in @$images.

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".

#!/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"; }
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>; my $ok; foreach (@pics){ $ok = $image->Read($_) and warn ($ok); } $image->Scale(geometry => '100x100'); $ok = $image->Write('thumb.png') and warn ($ok);
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); } 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);
So all you need to realize, is that to reuse an IM object, just undef @$images.

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


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: advice on OO and perlmagick by zentara
in thread advice on OO and perlmagick by stabu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.