[HELP] How to save the GD resource into MySQL.
Moderator: General Moderators
[HELP] How to save the GD resource into MySQL.
I created a image and got a GD resource. Can anybody tell me how to save the image which i created into database?
Thanks!
Thanks!
Re: [HELP] How to save the GD resource into MySQL.
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.
i'm afraid it's not efficient.tasairis wrote: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.
And how do you know that? Because last I knew it was more efficient than doing it your way.00061205 wrote:i'm afraid it's not efficient.tasairis wrote: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.
OK,i'll try, thank you for your reply.tasairis wrote:And how do you know that? Because last I knew it was more efficient than doing it your way.00061205 wrote:i'm afraid it's not efficient.tasairis wrote: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.
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.
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.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
Code: Select all
$im = imagecreate(500,500);
$red = imagecolorallocate($im, 255,0,0);
imagefilledrectangle($im,0,0,500,500,$red);
Is there a way to transform the GD resource type $im to string type?
-
Tellurian7
- Forum Newbie
- Posts: 1
- Joined: Fri Dec 19, 2008 4:27 am
Re: [HELP] How to save the GD resource into MySQL.
Hi,
(First, sorry for my bad english, i'm french.
)
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
(First, sorry for my bad english, i'm french.
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.
There's no "imagestring" like what you want. Images have different formats thus all those imagepng/imagegif/etc functions.
Use output buffering.
And next time don't hijack someone else's thread for your own question, even if the two are related.
Use output buffering.
Code: Select all
ob_start();
imagepng($oImage);
$string = ob_get_contents();
ob_end_clean();
// $string is the image in PNG format