|
-
May 4th, 2003, 07:00 PM
#1
Thread Starter
Junior Member
resizing an image with perl...
hi
i've been looking for this for more than 2 years now!
i need a little cgi script (or perl, i dont know the difference really) to resize a jpg image to specified dimentions... i found a PHP script for that job but unfortunately it didn't work, and PHPers couldnt help..
please, if you can help me, i need a little script which i can call from HTML like this:
<img src="/cgi-bin/getthumb.pl?w=150&h=250&img=/path/img.jpg">
it should take img.jpg which may be of any size and resize it to the specified dimentions in a way that the resulting thumb is not larger than w * h pixels.
after some web search, i found the following peace of code which i could extract from the original project IDS (image display system). it maybe of any help to u:
Code:
# Image Display System Shared Module 7/27/2001
# John Moose [email protected]
# Ashley M. Kirchner [email protected]
--- cut ---
##---------------------------------------------------------------------------------------------------
my $foreground = Image::Magick->new;
my($x);
my($xSize, $ySize) = $foreground->Get('width', 'height'); # Get the picture's dimensions
#Return if ImageMagick is dying on the image we selected
return unless (defined $ySize && $ySize && defined $xSize && $xSize);
my ($scaleFactor, $displayX, $displayY);
if ($xSize > $ySize) {
$displayX = int($xSize * (76/$ySize));
$displayY = 76;
if ($displayX < 51) {
$displayX = 51;
$displayY = int($ySize * (51/$xSize));
}
} else {
$displayX = 51;
$displayY = int($ySize * (51/$xSize));
if ($displayY < 76) {
$displayX = int($xSize * (76/$ySize));
$displayY = 76;
}
}
$x = $foreground->Scale(width=>$displayX, height=>$displayY);
die "$x" if "$x";
my($leftedge) = ($displayX - 51);
if ($leftedge > 0) {
$leftedge = int($leftedge / 2);
} else {
$leftedge = 0;
}
my($topedge) = ($displayY - 76);
if ($topedge > 0) {
$topedge = int($topedge / 2);
} else {
$topedge = 0;
}
$x = $foreground->Crop(width=>51, height=>76, x=>$leftedge, y=>$topedge);
die "$x" if "$x";
##---------------------------------------------------------------------------------------------------
many thanks for your help.
Sam,
Yusran Enhanced Solutions
http://yusran.com
Tel: +963-11-4464418
Cell: +963-94-507061
Get your free email address from http://email.yusran.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|