Hello.
I’ve a Perl script I use ImageMagick with.
I use it to upload photos - (image type: jpg), set to resize/scale to: 450px by width –which works great.
Now I want to add another field (logo) to upload image –BUT the size of this image will be only: 150px in width. (images type: gif, jpg, png ),
How can do this?
How/what command do I use to resize/scale the second image (which can also be a jpg) to a different size (but do resize to proportional to 150px width?
This is the ImageMagick codes in I’ve in my Perl currently:
Section 1:
#ImageMagick stuff
if($extension=~/jpeg|jpg/i)
{
MakeThumbnail($uploadsdir.$OUTfilename, $uploadsdir.MakeThumbnailName($OUTfilename));
}
#ImageMagick stuff end
section 2:
#ImageMagickStart
#conversion subroutine. takes 2 args - source filename and the thumbnail filename
sub MakeThumbnail
{
my($Filename)=@_;
#desired thumbnal width
my $ThumbWidth = 450;
#JPEG quality. 0-100, 100 is the best image quality, 0 is the best compression
my $Quality = 60;
my $ThumbName = MakeThumbnailName($Filename);
my $Image = new Image::Magick;
$Image->Read($Filename);
my $Width = $Image->Get("width")+0;
my $Height = $Image->Get("height")+0;
my $Scale = $ThumbWidth/$Width;
$Image->Resize(width=>$ThumbWidth, height=>$Height*$Scale);
$Image->Set(quality=>$Quality);
$Image->Write($ThumbName);
$Mode = (stat($ThumbName))[2];
rename($ThumbName, $Filename);
}
#function that adds "_1" to the thumbnail name
sub MakeThumbnailName
{
my($Name)=@_;
my($Filename, $Ext)=($Name=~/^(.*)\.(\w+)$/);
return $Filename."_1.jpg";
}
#ImageMagickEnd
Thanks for you help and instruction.
Campo