Page 1 of 1

[HELP] How to save the GD resource into MySQL.

Posted: Thu Nov 13, 2008 9:41 pm
by 00061205
I created a image and got a GD resource. Can anybody tell me how to save the image which i created into database?
Thanks!

Re: [HELP] How to save the GD resource into MySQL.

Posted: Thu Nov 13, 2008 10:38 pm
by requinix
It'd be better for you to dump that image into a file and store the filename instead.

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Nov 14, 2008 12:56 am
by 00061205
tasairis wrote:It'd be better for you to dump that image into a file and store the filename instead.
i'm afraid it's not efficient.

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Nov 14, 2008 1:39 am
by requinix
00061205 wrote:
tasairis wrote:It'd be better for you to dump that image into a file and store the filename instead.
i'm afraid it's not efficient.
And how do you know that? Because last I knew it was more efficient than doing it your way.

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Nov 14, 2008 6:48 am
by 00061205
tasairis wrote:
00061205 wrote:
tasairis wrote:It'd be better for you to dump that image into a file and store the filename instead.
i'm afraid it's not efficient.
And how do you know that? Because last I knew it was more efficient than doing it your way.
OK,i'll try, thank you for your reply.

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Nov 14, 2008 9:05 am
by chopsmith
I, too, prefer the method suggested by tasairis. However, if you want to save the image to the db, just use the BLOB field type: http://dev.mysql.com/doc/refman/5.0/en/blob.html

Re: [HELP] How to save the GD resource into MySQL.

Posted: Sat Nov 15, 2008 1:16 am
by 00061205
chopsmith wrote:I, too, prefer the method suggested by tasairis. However, if you want to save the image to the db, just use the BLOB field type: http://dev.mysql.com/doc/refman/5.0/en/blob.html
yeah, i know use the BLOB type but how to get the image data from the GD resource? I can't just save the GD resource to the db.

Code: Select all

 
$im = imagecreate(500,500);
$red = imagecolorallocate($im, 255,0,0);
imagefilledrectangle($im,0,0,500,500,$red);
 
If just save the $im to the db the image data actually not save to the db.
Is there a way to transform the GD resource type $im to string type?

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Dec 19, 2008 4:37 am
by Tellurian7
Hi,

(First, sorry for my bad english, i'm french. :D )

I'm programming a php class with image manipulation functions, and i have the same answer about saving gd image resource in a BLOB field ...
Then i'm lookin for a function called like "imagestring" (like imagejpeg, imagepng.., not the text writing function).
But this function musn't use thinks like this (bad performance) :

imagepng($oImage, "temp.png"); $sData = file_get_content("temp.png") ...

Any idea? Thanks

Re: [HELP] How to save the GD resource into MySQL.

Posted: Fri Dec 19, 2008 5:39 am
by requinix
There's no "imagestring" like what you want. Images have different formats thus all those imagepng/imagegif/etc functions.

Use output buffering.

Code: Select all

ob_start();
imagepng($oImage);
$string = ob_get_contents();
ob_end_clean();
 
// $string is the image in PNG format
And next time don't hijack someone else's thread for your own question, even if the two are related.