#!/usr/local/bin/perl use Image::Magick; ## turn off buffer .... $| = 1; my $src = Image::Magick->new; $src->Read('bird.gif'); # Create the thumbnail, where the biggest side is 50 px my ($thumb,$x,$y) = create($src,150); print "Content-type: image/gif\n\n"; binmode STDOUT; $thumb->Write('gif:-'); exit; sub create { my ($img,$n) = (shift,shift); my ($ox,$oy) = $img->Get('width','height'); my $r = $ox>$oy ? $ox / $n : $oy / $n; $img->Resize(width=>$ox/$r,height=>$oy/$r); return $img, sprintf("%.0f",$ox/$r), sprintf("%.0f",$oy/$r); }