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