note 52099 added to function.getimagesize
| From: | ajreading at classixshop dot com | Date: | Thu, 21 Apr 2005 08:30:29 +0000 |
| Subject: | note 52099 added to function.getimagesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88310@lists.php.net to get a copy of this message | ||
A simple piece of code i wrote to proportionally resize an image to a max height and width then
display it
<?php
// Max height and width
$max_width = 100;
$max_height = 100;
// Path to your jpeg
$upfile '/path/to/file.jpg';
Header("Content-type: image/jpeg");
$size = GetImageSize($upfile); // Read the size
$width = $size[0];
$height = $size[1];
// Proportionally resize the image to the
// max sizes specified above
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
// Increase memory limit to support larger files
ini_set('memory_limit', '32M');
// Create the new image!
$src = ImageCreateFromJpeg($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageJpeg($dst);
// Destroy the images
ImageDestroy($src);
ImageDestroy($dst);
?>
----
Manual Page -- http://www.php.net/manual/en/function.getimagesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52099
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52099&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52099&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52099&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52099&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52099&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52099&report=yes
Search -- http://master.php.net/manage/user-notes.php