in reply to Returning jpg works, png NOT

Note that this serves no purpose:

binmode IMAGE; ... open IMAGE, $file_name or die "ERROR $!";

You need to appüly binmode after opening a file (but before reading from it):

open IMAGE, $file_name or die "ERROR $!"; binmode IMAGE;

Replies are listed 'Best First'.
Re^2: Returning jpg works, png NOT
by ambrus (Abbot) on Jul 06, 2011 at 09:13 UTC

    Good catch! That, in fact, could explain the symptoms, because the magic bytes of the PNG format ("\x89PNG\r\n\cz\n") is specifically designed such that it becomes corrupted if you mess up line endings, whereas a small jpg image might not contain "\r\n" anywhere at all so it may survive being read in text mode.

Re^2: Returning jpg works, png NOT
by membender (Novice) on Jul 06, 2011 at 18:49 UTC

    Thank you, Corion! This solved it, and "good catch" indeed...