...

View Full Version : Php GD save in database help..



uncleroxk
12-15-2008, 05:24 AM
Hi, i know that you can save a image create by the GD library to the filesystem by:

imagejpeg($image_resource, $newName");

but how do i save it to the database?
and how do i get the filesize of the generated image?


thank you.

Fou-Lu
12-15-2008, 06:25 AM
Capture its output using an output buffer:


ob_start();
imagejpeg($imJPGHandle, null, 100);
$obImageData = ob_get_contents();
ob_end_flush(); // use ob_end_clean if you don't want to display the image


Alternatively, you could write to a file, read it, copy it, and unlink it. Seems like too much work for my liking :P

To get the size, $obImageData (in my example) should be a binary string. I believe you can simply use strlen on it. If it doesn't work, I'll figure out a solution for you (can't test where I am).

kokjj87
12-15-2008, 06:56 AM
To add on to fou-lu.... =)


ob_start();
imagejpeg($imJPGHandle, null, 100);
$obImageData = ob_get_contents();
$obImageSize = ob_get_length(); //get the file size in byte
ob_end_flush(); // use ob_end_clean if you don't want to display the image



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum