note 48624 added to function.imagecopyresampled
| From: | afrowuk at tiscali dot co dot uk | Date: | Sun, 02 Jan 2005 15:17:22 +0000 |
| Subject: | note 48624 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82601@lists.php.net to get a copy of this message | ||
This simple function resizes a JPG image file giving just a maximum width, and resizes keeping the
aspect ratio. This is useful if you have to resize a JPG image that must fit the width of i.e. a div
element, but doesn't have to have a maximum height.
<?
function resizeJPG($jpgFile, $width) {
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, $jpgFile, 100);
}
?>
-Stu
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48624
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48624&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48624&report=yes
Search -- http://master.php.net/manage/user-notes.php