#same thing, using GD libary sub make_thumbnail_GD{ # receives: # file source (absolute path on machine) # file target out (absolute path on machine) # restriction # restriction type # quality my ($src,$out,$restriction,$restrict_type,$quality)=@_; # both restrict to height and width :both won't go over this.. # width restrict to width # height restrict to height # square square - will crop sides or top and bottom to fit. neat. my $img = GD::Image->newFromJpeg($src); my ($w,$h) = $img->getBounds(); # find dimensions #if width is bigger then height, we use restrict to w if ($restrict_type eq 'both'){ if ($w>$h){ $restrict_type='width'; } else { $restrict_type='height'; } } my $newh; my $neww; # initialize new dimensions # not used if 'square' if ($restrict_type eq 'height') { $neww=(($w*$restriction)/$h); $newh=$restriction; } if ($restrict_type eq 'width') { $newh=(($h*$restriction)/$w); $neww=$restriction; } if ($restrict_type ne 'square'){ my $newimg = new GD::Image($neww,$newh); $newimg->copyResized($img,0,0,0,0,$neww,$newh,$w,$h); open(FILE, "> $out") || die; print FILE $newimg->jpeg; } else { #square my ($cut,$xcut,$ycut); if ($w>$h){ $cut=$h; $xcut=(($w-$h)/2); $ycut=0; } if ($w<$h){ $cut=$w; $xcut=0; $ycut=(($h-$w)/2); } my $newimg = new GD::Image($restriction,$restriction); $newimg->copyResized($img,0,0,$xcut,$ycut,$restriction,$restriction,$cut,$cut); open(FILE, "> $out") || die; print FILE $newimg->jpeg; } }