RE: [PHP] resize a blob image?????
| From: | James Moore | Date: | Tue, 29 Aug 2000 21:02:41 +0000 |
| Subject: | RE: [PHP] resize a blob image????? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14237@lists.php.net to get a copy of this message | ||
> > :-)
> >
> > I thought of that already but how is it done with only this code?
> >
>
> Well, you could use getimagesize() on an actual file, but you are getting
> the file from the BLOB column, so it makes it more tricky.
>
> A dirty hack on this could be to create the image file from the blob, and
> then get the dimensions using getimagesize(). Then you can show the image
> and change your IMG tags.
>
For this I will persume that the image data is in $img_data, it also reqires
gd.
==== UNTESTED CODE =========
/* Create Temp File Name */
$filename = $tmpnam($TMP_DIR,"img");
/* Create temp file */
$fp = fopen($filename,"r");
/* Write out data */
fwrite($fp,$img_data);
fclose($fp);
$image_atts = getimagesize($filename);
$x_size = $image_atts[0];
$y_size = $image_atts[1];
/* I am persuming gif is used else change next functions as needed */
$img_src = imagecreatefromgif($filename);
$new_x = .5 * $x_size; //Image is now .5 the width
$new_y = .5 * $y_size; // " " " " " height
/* Create Final Image */
$dest_img = imagecreate($new_x,$new_y);
/* Copy and resize image */
imagecopyresized($dest_img,$img_src,0,0,0,0,$new_x,$new_y,$x_size,$y_size);
/*delete file */
if(fileexists($filename))
unlink($filename);
========================
This will reduce the image by 1/2 change the .5 to what ever value you
want... You can now use ImageGIF/ImagePNG to output it to the browser.
HTH
James