in reply to Pixel setting oddity - Image:Magick

In  $img_gry->Set('pixel[$col,$row]' => 'rgb($sub_red, $sub_green, $sub_blue )'); the single quotes prevent interpolation which means Image::Magick is given the strings '$col', and '$row' instead of the values you expect. I didn't read the documentation to see if anything else is wrong, but this does look highly suspicious. Aren't you getting any warnings for that? I'm surprised Image::Magick doesn't complain about the invalid input.

Replies are listed 'Best First'.
Re^2: Pixel setting oddity - Image:Magick
by afoken (Chancellor) on May 11, 2015 at 12:30 UTC
    Aren't you getting any warnings for that? I'm surprised Image::Magick doesn't complain about the invalid input.

    The posted code has a bare string eval without any error checks ($@), so most errors will be silent. Also, Image::Magick requires a lot of manual error checks because it does not use perl's exception mechanism (i.e. die), but instead requires checking return values (as in C). This is documented in http://www.imagemagick.org/script/perl-magick.php#exceptions. The posted code lacks those checks, too.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Thanks for the info on exception handling with Image::Magick!

      And yes, merrymonk fails to check $@ after the eval, but there wouldn't have been a warning there since this actually works (as in this case the variables are actually in a double quote context). And on the topic of safety and error checking, it does look like the code is not run under strict and warnings ; which would have done nothing for this particular case, but are still very helpful safety nets.

        Thank you for that explanation. Indeed is was the single quotes that were stopping it working. When I changed these to 4 double quotes all was well!