It looks like the only way to use resize is to use the command line. I don't know how to make that happen with perl driving the logic other than through a system command followed by some script you've written. That's what I attempt to do here, but I seem to be hung up on a printf statement. Why is the %s not working in this printf call? I can see on my terminal that the loop is loading all the images in the directory, and that the logic for entering into the inner control seems to work, that is filesizes less than the target value are ignored, which gets rid of . and .. too. What follows is the routine followed by the helper script it creates.
sub resize_images { use 5.010; use Path::Class; use Image::Magick; my ($rvars) = shift; my %vars = %$rvars; $vars{"target"}= 100; $vars{"bias"}= 2; $vars{"helpscript"}= "helper1.sh"; my $file2 = $vars{"helpscript"}; my $path = $vars{"to_images"}; open( my $fh, ">", $file2 ) or die("Can't open $file2 for writing: $!"); my $cd = "cd $path \n"; print $fh $cd; my $ls = "ls -lt >>text1.txt\n"; print $fh $ls; opendir my $hh, $path or warn "warn $!\n"; while (defined ($_ = readdir($hh))){ my $image = Image::Magick->new; my $file = file($path,$_); $image->ReadImage($file); $x = $image->Get('filesize'); my $k = $x/1024; say "$file has filesize of $x bytes or $k k"; if ($k>$vars{"target"}){ say "file is $file"; my $ratio = $k/($vars{"target"}-$vars{"bias"}); say "ratio is $ratio"; my $percent = 100/$ratio; say "percent is $percent"; my $mogrify_spec = "mogrify -resize %2.2f\% %s\n"; printf $fh $mogrify_spec, $percent, $file; #printf $fh "file is $file\n"; } close $fh; } }
$ cat helper1.sh cd /home/fred/Desktop/root3/pages/raiders/template_stuff/aimages ls -lt >>text1.txt mogrify -resize 40.04%s $
In reply to Re^3: Using ImageMagick effectively
by Aldebaran
in thread Using ImageMagick effectively
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |