note 20028 added to function.imagecopyresized
| From: | jonas at hoglin dot com | Date: | Tue, 19 Mar 2002 21:05:07 +0000 |
| Subject: | note 20028 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27971@lists.php.net to get a copy of this message | ||
Here is a function that will resize and move an uploaded image. The resize will not deform the
image. See the other notes for a similar but for GIF.
function resizeJPEG($imagefile, $newName, $limitWidth, $limitHeight) {
$src_img = imagecreatefromjpeg($imagefile);
$imageInfo = getimagesize($imagefile);
$width = $imageInfo[0];
$height = $imageInfo[1];
$checkSize = $width / $height;
//
//If the image is wider than heigh
//$checkSize > 1
if ($checkSize > 1) {
$newWidth = $limitWidth;
$newHeight = ($limitWidth / $width) * $height;
}
//
//If the image is heigher than wide
//$checkSize < 1
if ($checkSize < 1) {
$newHeight = $limitHeight;
$newWidth = ($limitHeight / $height) * $width;
}
//
//If the image is same width as height
//$checkSize == 1
if ($checkSize == 1) {
$newWidth = $limitWidth;
$newHeight = $limitHeight;
}
$dst_img = imagecreate($newWidth,$newHeight);
imagecopyresized($dst_img,$src_img,0,0,0,0,$newWidth,
(same line) $newHeight, imagesx($src_img),imagesy($src_img));
//
//Output the image
//
imagejpeg($dst_img,"./dynamicImages/$newName");
//
//cleanup
//
ImageDestroy($src_img);
ImageDestroy($dst_img);
}
--
http://www.php.net/manual/en/function.imagecopyresized.php
http://master.php.net/manage/user-notes.php?action=edit+20028
http://master.php.net/manage/user-notes.php?action=delete+20028
http://master.php.net/manage/user-notes.php?action=reject+20028