note 102746 added to function.imagecopyresampled
| From: | vanadragos at yahoo dot com | Date: | Thu, 03 Mar 2011 11:54:34 +0000 |
| Subject: | note 102746 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177524@lists.php.net to get a copy of this message | ||
the first function to resize the image on the page is faulty
this is a better function that works and also has a second pass because some images did not get
trough properly in the first pass
function resizeImage($src, $w, $h) {
// Get the current size
$width = ImageSx($src);
$height = ImageSy($src);
// If one dimension is right then nothing to do
// if($width <= $w || $height <= $h)
// return($src);
// Calculate new size
if(($w - $width) > ($h - $height)) { // use height
$s = $h / $height;
$nw = round($width * $s);
$nh = round($height * $s);
}
else { // Use width
$s = $w / $width;
$nw = round($width * $s);
$nh = round($height * $s);
}
// Return the new image
$nwidth = $nw;
$nheight = $nh;
// If one dimension is right then nothing to do
// if($width <= $w || $height <= $h)
// return($src);
// Calculate new size
if(($w - $nwidth) > ($h - $nheight)) { // use height
$s = $h / $nheight;
$nw = round($nwidth * $s);
$nh = round($nheight * $s);
}
else { // Use width
$s = $w / $nwidth;
$nw = round($nwidth * $s);
$nh = round($nheight * $s);
}
$im = ImageCreateTrueColor($nw, $nh);
ImageCopyResampled($im, $src, 0, 0, 0, 0, $nw, $nh, $width, $height);
return($im);
}
----
Server IP: 69.147.83.197
Probable Submitter: 86.106.49.77
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/102746
Del: integrated -- https://master.php.net/note/delete/102746/integrated
Del: useless -- https://master.php.net/note/delete/102746/useless
Del: bad code -- https://master.php.net/note/delete/102746/bad+code
Del: spam -- https://master.php.net/note/delete/102746/spam
Del: non-english -- https://master.php.net/note/delete/102746/non-english
Del: in docs -- https://master.php.net/note/delete/102746/in+docs
Del: other reasons-- https://master.php.net/note/delete/102746
Reject -- https://master.php.net/note/reject/102746
Search -- https://master.php.net/manage/user-notes.php