#!/usr/bin/perl # (c) Copyright 2003-2005 by Ortwin Glück # This is free software. Free as in "freedom" and "free beer". use Image::Magick; if ($#ARGV < 1) { print <new; $img->Read($file); ($width, $height) = $img->Get('width', 'height'); if ($factor > 0) { $width = $width / $factor; $height = $height / $factor; } elsif (($fwidth > 0) && ($fheight > 0)) { my $wf = $fwidth / $width; my $hf = $fheight / $height; if ($wf * $height > $fheight) { $width = $width * $hf; $height = $fheight; } else { $width = $fwidth; $height = $height * $wf; } } elsif ($fwidth > 0) { my $wf = $fwidth / $width; my $hf = $fwidth / $height; if ($wf < $hf) { $width = $fwidth; $height = $height * $wf; } else { $width = $width * $hf; $height = $fwidth; } } elsif ($fheight > 0) { my $wf = $fheight / $width; my $hf = $fheight / $height; if ($wf < $hf) { $width = $width * $hf; $height = $fheight; } else { $width = $fheight; $height = $height * $wf; } } else { die("Invalid size parameter"); } $img->Scale(width=>$width, height=>$height); if (($factor == 0) && ($bgcol ne '')) { $img->Set(bordercolor=>$bgcol); $framew = ($fwidth - $width) / 2; $frameh = ($fheight - $height) / 2; if (($framew != 0) || ($frameh != 0)) { if ($frameh == 0) { $frameh++; # workaround bug to prevent a black image } $img->Frame(width=>$framew, height=>$frameh, inner=>0, outer=>0, fill=>$bgcol); } } $img->SetAttribute(quality=>$quality); $img->Write("$ddir/${prefix}${image}"); if ($verbose) { print "$image\n"; } }