#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $filename = shift; my $target = $filename; $target =~ s/(\..*$)/_thumb$1/; my $image = new Image::Magick; $image->Read( $filename ); my ($width, $height) = $image->get('width', 'height'); if ( $width > $height ) { my $diff = $width - $height; $width -= $diff; my $xoffset = ( $diff / 2 ); $image->Crop( geometry => "${width}x$height+$xoffset+0" ); } else { my $diff = $height - $width; $height -= $diff; my $yoffset = ( $diff / 2 ); $image->Crop( geometry => "${width}x$height+0+$yoffset" ); } $image->Scale( width => 100, height => 100 ); $image->Write( $target );