##
my $image = Image::Magick->new;
$image->Read($file);
my ($width, $height) = $image->Get('width', 'height');
if($width < $height) {
my $nh = $size*$height/$width;
$image->Resize(width => $size, height => $nh);
} else {
my $nw = $size*$width/$height;
$image->Resize(width => $nw, height => $size);
}
$image->Crop(width => $size, height => $size);
####
$image->Set(Gravity => 'Center');