in reply to Re: Using ImageMagick effectively
in thread Using ImageMagick effectively

Installing perlmagick was what I needed. I've written a routine that iterates through the images folder, but I fail to create and assign the object correctly:

sub resize_images { use 5.010; use Path::Class; use Image::Magick; my ($rvars) = shift; my %vars = %$rvars; opendir my $hh, $vars{to_images} or warn "warn $!\n"; while (defined ($_ = readdir($hh))){ my $image = Image::Magick->new; $image->ReadImage($_); $x = $image->Get('filesize'); say "$_ has filesize of $x"; } }

Output:

Screenshot from 2014-08-21 13:10:18.png has filesize of Screenshot from 2014-09-25 17:14:08.png has filesize of Screenshot from 2014-08-21 13:22:42.png has filesize of zbears.jpg has filesize of . has filesize of .. has filesize of yjj.jpg has filesize of

Fishing for tips....

Replies are listed 'Best First'.
Re^3: Using ImageMagick effectively
by tangent (Parson) on Sep 26, 2014 at 03:12 UTC
    You need to prepend the directory to the filename (see readdir), and you can check if the read was successful:
    my $dir = $vars{to_images}; ... my $err = $image->ReadImage("$dir/$_"); warn "$err" if $err;
    Also, might be better to filter out the non-image files before passing to Image::Magick.