Hi,
I'm having trouble getting a little Perl program to work. It doesn't want to update some variables inside a foreach loop. '$image->Read($listitem);' works in the first iteration, but isn't updated next time around.
Pardon if this the solution is obvious, this is my first attempt at perl.
#!/usr/local/bin/perl
use Image::Magick;
my $progdir = 'c:/CoverArt/';
my $origdir = 'c:/CoverArt/Originals/';
my $pdadir = 'c:/CoverArt/PDA/';
chdir( $progdir ) or die "Cant chdir to $dir $!";
unlink("nytt.jpg");
chdir;
my($image, $x);
$gradient = Image::Magick->new;
$bottombar = Image::Magick->new;
$shine = Image::Magick->new;
$shine2 = Image::Magick->new;
$main = Image::Magick->new;
$main2 = Image::Magick->new;
$image = Image::Magick->new;
$main->Read('main.jpg');
$shine->Read('shine.png');
$bottombar->Read('bottombar.png');
$gradient->Read('gradient.png');
chdir( $origdir ) or die "Cant chdir to $dir $!";
opendir MYDIR, ".";
@contents = grep !/^\.\.?$/, readdir MYDIR;
closedir MYDIR;
foreach my $listitem ( @contents )
{
print $listitem . "\n";
$shine2 = $shine;
$main2 = $main;
chdir( $origdir ) or die "Cant chdir to $dir $!";
$image->Read($listitem);
$width = $image->Get('columns');
$height = $image->Get('rows');
$width = (305/$height)*$width;
$image->AdaptiveResize(width=>$width,height=>305);
$shine2->AdaptiveResize(width=>$width);
$image->Composite(image=>$shine,compose=>'over');
$image->Border(bordercolor=>'white',width=>'1', height=>'1');
$reflection = $image->clone();
$reflection->Flip();
$main2->Composite(image=>$image,compose=>'over', y=>-20, gravity=>'center');
$main2->Composite(image=>$reflection,compose=>'blend', y=>285, gravity=>'center');
$main2->Composite(image=>$gradient,compose=>'over', gravity=>'south');
$main2->Composite(image=>$bottombar,compose=>'over', gravity=>'south');
chdir( $pdadir ) or die "Cant chdir to $dir $!";
$main2->Write($listitem);
}
I'm having trouble getting a little Perl program to work. It doesn't want to update some variables inside a foreach loop. '$image->Read($listitem);' works in the first iteration, but isn't updated next time around.
Pardon if this the solution is obvious, this is my first attempt at perl.
#!/usr/local/bin/perl
use Image::Magick;
my $progdir = 'c:/CoverArt/';
my $origdir = 'c:/CoverArt/Originals/';
my $pdadir = 'c:/CoverArt/PDA/';
chdir( $progdir ) or die "Cant chdir to $dir $!";
unlink("nytt.jpg");
chdir;
my($image, $x);
$gradient = Image::Magick->new;
$bottombar = Image::Magick->new;
$shine = Image::Magick->new;
$shine2 = Image::Magick->new;
$main = Image::Magick->new;
$main2 = Image::Magick->new;
$image = Image::Magick->new;
$main->Read('main.jpg');
$shine->Read('shine.png');
$bottombar->Read('bottombar.png');
$gradient->Read('gradient.png');
chdir( $origdir ) or die "Cant chdir to $dir $!";
opendir MYDIR, ".";
@contents = grep !/^\.\.?$/, readdir MYDIR;
closedir MYDIR;
foreach my $listitem ( @contents )
{
print $listitem . "\n";
$shine2 = $shine;
$main2 = $main;
chdir( $origdir ) or die "Cant chdir to $dir $!";
$image->Read($listitem);
$width = $image->Get('columns');
$height = $image->Get('rows');
$width = (305/$height)*$width;
$image->AdaptiveResize(width=>$width,height=>305);
$shine2->AdaptiveResize(width=>$width);
$image->Composite(image=>$shine,compose=>'over');
$image->Border(bordercolor=>'white',width=>'1', height=>'1');
$reflection = $image->clone();
$reflection->Flip();
$main2->Composite(image=>$image,compose=>'over', y=>-20, gravity=>'center');
$main2->Composite(image=>$reflection,compose=>'blend', y=>285, gravity=>'center');
$main2->Composite(image=>$gradient,compose=>'over', gravity=>'south');
$main2->Composite(image=>$bottombar,compose=>'over', gravity=>'south');
chdir( $pdadir ) or die "Cant chdir to $dir $!";
$main2->Write($listitem);
}