use strict; use warnings; use Imager::Simple; use Imager::Filter::Autocrop; my $imgdata = undef; open(IN, '<', 'example.jpg'); binmode(IN); { local $/ = undef; $imgdata = } close(IN); my $img = Imager::Simple->new(); $img->read(\$imgdata) or die "read: ".$img->errstr(); $img->autocrop(fuzz=>20) or die "autocrop: ".$img->errstr(); $img->write('out.jpg') or die "writing: ".$img->errstr();