PHP: Convert Image to String?

I'm building a PHP based Image Manipulation Script. Offering Functions like Rotating, Cropping and Resizing. To execute the script you enter "updateimage.php?imgID=IMG6537456&rotate=180". The script loads the image from a mysql table using "$db_img = imagecreatefromstring($row['img']);" then the scripts executes the required functions to manipulate the image then I would like to update the mysql table to reflect the manipulations.

Just simply calling "UPDATE images SET `img` = '$db_img' WHERE imgID='$imgID'" works but the image is corrupt or basically can not be redisplayed. The source image is 76 KiB but the updated image is only 4 K. Which I think shows that there is a problem. Basically I'm looking for a answer that would do the reverse of imagecreatefromstring(). I have seen solutions to using commands like $db_img = addslashes($db_img); or $db_img = mysql_escape_string($db_img);. I have not been able to find a working solutions yet. Let me remind you this is a Image loaded from mysql in the first place not loaded from file.
$db_img = base64_encode($db_img); results in "Warning: base64_encode() expects parameter 1 to be string, resource given in updateimage.php on line 95" and I would prefer not to write and read the image to a temp file. Even if I did write and read the image don't I still need to convert it to some kind of string.
 
You may have to write the image resource to a file (just a temp will do), then read that into a string and save that.
Also, base64_encoding the string before submitting to database might be a good idea, somethng like $db_img= base64_encode($db_img); then the update.
 
You may have to write the image resource to a file (just a temp will do), then read that into a string and save that.
Also, base64_encoding the string before submitting to database might be a good idea, somethng like $db_img= base64_encode($db_img); then the update.
 
You may have to write the image resource to a file (just a temp will do), then read that into a string and save that.
Also, base64_encoding the string before submitting to database might be a good idea, somethng like $db_img= base64_encode($db_img); then the update.
 
Back
Top