Image resize with database
| From: | Steve Vernon | Date: | Mon, 16 Dec 2002 13:52:27 +0000 |
| Subject: | Image resize with database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128398@lists.php.net to get a copy of this message | ||
(PHP 4.23, GD 1.6.2 or higher)
Hiya,
I have code to place the picture in a database, and I normally shrink it
when the user requests a picture. What I would like it to change to is that
it should shrink or expand the picture to be 300 pixels wide and then place
it into the database. I thought the function below would work to do to
return a text resized version.
It does sort of works, but makes a picture where only part of it is the
picture (top part), the rest is blank.
Any help would be gr8!
THanks,
Steve
function shrink_picture($tmp_name,$size,$name)
{
$result = ereg(".gif$",strtolower($name));
if($result)
{
$img = imagecreatefromgif($tmp_name);
}
else
{
$img = imagecreatefromjpeg($tmp_name);
}
$width = imagesx($img);
$height = imagesy($img);
$new_height = abs(300.0 * ($height/$width));
$new_img = imagecreate(300, $new_height );
imagecopyresized($new_img,$img,0,0,0,0,300,$new_height,imagesx($img),imagesy
($img));
imagejpeg($new_img,$tmp_name."a",70);
imagedestroy($new_img);
imagedestroy($img);
$data = addslashes(fread(fopen($tmp_name."a","r"),$size));
return $data;
}