Page 1 of 1

Save gd image to database

Posted: Mon Aug 11, 2008 12:26 pm
by Dynamis
Here is what I am doing:
Allow user to upload image.
I create a thumbnail of the image.
Want to save thumbnail to database.

A little code:

Code: Select all

 
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
 
So as you can see, dst_img is a truecolor gd image. How can I get the bytes from that to put into the database? I know I could save it as a temporary file, read the file bytes, save those, then delete the temporary file, but I would rather not do that.

Re: Save gd image to database

Posted: Mon Aug 11, 2008 1:01 pm
by onion2k
Use the output buffer. Eg

Code: Select all

ob_start();
imagejpeg($dst_img);
$image = ob_get_clean();
 
$image will contain the image in jpeg format.