Might need to open the filehandle in binary mode:
Straight from the binmode
documentation: "In other words: regardless of platform, use binmode() on binary data, like images, for example."
use strict;
use warnings;
use autodie;
...
open my $fh, '>:raw', 'test.jpeg';
binmode $fh;
print $fh $imgdata;
close $fh;
Read PerlIO
for more information on opening files in different modes. I included both '>:raw'
and binmode $fh
in the above code to increase familiarity, but these indicators are actaully equivalent as you'd read in PerlIO. So feel free to use just one or the other.