note 48387 added to function.imagecopyresampled
| From: | jeremyaatlordcodotcom at osu1 dot php dot net | Date: | Tue, 21 Dec 2004 18:12:11 +0000 |
| Subject: | note 48387 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82139@lists.php.net to get a copy of this message | ||
This code will fit an image into an area and maintain aspect ratio.
<?php
$filename = "image.jpg";
// Set a maximum height and width or use numbers from another source
$widthset = 600;
$heightset = 400;
// Get current dimensions
list($width_orig, $height_orig) = getimagesize($filename);
// Get dimension change ratios
$width_ratio = ($widthset / $width_orig);
$height_ratio = ($heightset / $height_orig);
// Figure out which one is the lesser
if ($width_ratio < height_ratio) {
$ratio = $width_ratio;
} else {
$ratio = $height_ratio;
}
//Apply the math to the original image sizes. From here you can use height_new and width_new on your
image wherever you like.
$height_new = $ratio * $height_orig;
$width_new = $ratio * $width_orig;
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48387
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48387&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48387&report=yes
Search -- http://master.php.net/manage/user-notes.php