On Sat, 17 Jan 2009 10:31:16 -0800
"David N. Lombard" <[email protected]> wrote:
>I want to replicate an image in an image object. I'm building a montage
>of either one or multiple images to print multi-label pages.
>
>In order to montage multiple copies of an image on a montage, the only
>thing I've found that works is to read the image file multiple times.
>For example,
>
> my $image = Image::Magick->new;
> $image->Read( $inf );
> $image->Read( $inf );
> $image->Read( $inf );
> $image->Read( $inf );
> my $montage = $image->Montage( tile=>"2x2", ... );
> $montage->Write( $outf );
>
>That works fine, but seems a little, well, lame. Can I just somehow
>replicate the images within $image? I tried
>
> $image->[1] = $image->[0];
>
>but that did nothing but confuse IM.
>
>Clone() wants to generate a new image object; the Blob functions also
>don't seem quite what I need.
>
>This is also important as I want to be able to generate an image to
>montage instead of always reading it from a file. Right now, all I can
>think to do is create the new image, write it to a file, and then read
>it back in, and that seems completely broken...
>
>I'm using Image::Magick 6.3.2.9
>
>--
>David N. Lombard
Hi, yeah I tried the $image->[1] = $image->[0]; technique
but it didn't want to work. The Clone worked, but there is
a glitch, where the clone doubles on each loop, so you may have
to adjust your loop math.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $inf = 'earthhal.jpg';
my $output_file = "$0.jpg";
my $image = Image::Magick->new();
$image->Read($inf);
# different results in loop
#my $p = $image->Clone();
print @$image[0],"\n";
for(1..4){
# push @$image, $p; # dosnt work the same
push @$image, $image->Clone();
}
print "@$image\n";
my ($final) = $image->Montage();
$final->Write($output_file);
__END__
I'm a bit confused about your last statement about constantly
needing to read from files..... you only need to read $inf once;
you can always store the image in a blob, which holds the
image in memory.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $imgfile = shift;
my $image = Image::Magick->new();
$image->Read($imgfile);
my $blob = $image->ImageToBlob();
#and the opposite
my $output = Image::Magick->new(magick=>'jpg');
$output->BlobToImage( $blob );
$output->Resize(geometry=>'160x120');
$output->Write('z.jpg');
#or if you want to write to stdout
#binmode STDOUT;
#$output->Write('jpg:-');
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://www.zentara.net~/zentaran/Remember_How_Lucky_You_Are.html
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users