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; } }