Hi, it's a little known fact-of-life that IM maintains a global stack of images that it uses for its own purposes, so you need to clear out the IM object after every run thru the loop. Whenever you read an image, it gets pushed into an internal array for storage. This useful sometimes, as in certain IM methods, all images can be processed by going thru this array. Of course, it also can get in the way sometimes, as you have seen. What you you probably need to do is undef @$my_IM_object, as shown here:
You can also read perldoc -q clear and read the first section "How do I clear out a package?".my $image = Image::Magick->new; foreach my $pic (@pics){ my $ok; $ok = $image->Read($pic) and warn ($ok); $image->Scale(geometry => '100x100'); $ok = $image->Write($thumb) and warn ($ok); # this is the key line undef @$image; #needed if $image is created outside loop
Of course, this is just my top-of-the-morning guess at your problem, because your code dosn't even look like it will run correctly with things like my $imagen($i) =. That dosn't match any data structure commonly used in Perl.
In reply to Re: Loop array with ImageMagick
by zentara
in thread Loop array with ImageMagick
by johnfl68
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |