Image::Magick

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
zemlik
Posts: 38
Joined: 2014-03-05T06:12:01-07:00
Authentication code: 6789

Image::Magick

Post by zemlik »

hello,
trying to understand the perl syntax I gathered some bits from the internet to make an array from a .csv file.
I'd like to combine all the images that are in a row,
I'm not sure if I can do them all at once as I've only combined 2 images before.

Code: Select all

composite -compose atop 1.png 2.png out.jpg
what would be the syntax in Image::Magick ?

Code: Select all

#!/bin/perl -w
use strict;
use Text::CSV_XS;
use Image::Magick;
use diagnostics;
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";
my $csv = Text::CSV_XS->new ({
binary => 1,
auto_diag => 1,
});
my $image = Image::Magick->new;
my @frm=();
my $ct=0;
my @x=();
my $f="";
my $y=0;
my $pic="";
open(my $data, '<:encoding(utf8)', $file) or die "Could not open '$file' $!\n";
while (my $fields = $csv->getline( $data )) {
for ($ct=0;$ct<=6;$ct++)
{
$frm[$y][$ct]=$fields->[$ct];
}
$y+=1;
}
if (not $csv->eof) {
$csv->error_diag();
}
close $data;
$pic=$image->Read($frm[6][1]);
$pic=$image->Write('x1.jpg');

that works in that it reads and writes but I'm struggling with the compose syntax.
zemlik
Posts: 38
Joined: 2014-03-05T06:12:01-07:00
Authentication code: 6789

Re: Image::Magick

Post by zemlik »

hello,
I should finish reading the perl book before doing this.
found syntax for composite so I can combine 2 images

Code: Select all

$level[$x][$i]=Image::Magick->new;
$level[$x][$i]->Read($cells[$x][$i]);
}
}
$level[30][2]->Composite(image=>$level[30][1],compose=>'over');
$level[30][2]->Write("output4.png");

but I am getting in knots wondering if I need to write each pair to disk and then build a new array or something.
in the documentaion there is this

Code: Select all

convert -size 100x100 xc:skyblue composite.gif
  composite -geometry  +5+10 balloon.gif composite.gif composite.gif
  composite -geometry +35+30 medical.gif composite.gif composite.gif
  composite -geometry +62+50 present.gif composite.gif composite.gif
  composite -geometry +10+55 shading.gif composite.gif composite.gif
Is there a syntax to do the same thing in perl ?
[edit]
ok this works. so I need to know syntax for $#array for multidimensional array.
and is there somewhere else to write the temp images ?

Code: Select all

$level[$x][$i]=Image::Magick->new;
$level[$x][$i]->Read($cells[$x][$i]);
}
$frame[$x]=Image::Magick->new;
}
$frame[5]=$level[5][2];
$frame[5]->Composite(image=>$level[5][1],compose=>'over');
$frame[5]->Write("output4.png");
$frame[5]->Composite(image=>$level[5][0],compose=>'over');
$frame[5]->Write("output5.png");

Last edited by zemlik on 2014-05-31T10:03:06-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image::Magick

Post by fmw42 »

I do not think so. You have to do them in pairs, I believe in most of the APIs, unless there is a multi-image flatten equivalent. But doubt that exists in the APIs. But I am not an API expert.
Post Reply