I have image in buffer after retrieving it from the Web:
my $img = $webapi->get('http://myserver.com/image/123423.jpg');
After the call, raw data is in the $img. I want to make sure the data represents image and not text, so I save it to a file on disk and run file command:
open my $fh, '>', '/tmp/images/rawdata.bin';
print $fh $img;
close $fh;
$res = `file /tmp/images/rawdata.bin`;
if ($res =~ 'GIF|JPEG|PNG') print "Image";
else "Not image";
How do I avoid saving raw data to file and do the work in memory?