Page 1 of 1

Getting string from image

Posted: Thu Oct 13, 2005 9:26 pm
by MathewByrne
Hi,

Been trying to find a way of inserting an uploaded image into a database. The image is resized before being put into the sql database.

What I need is some way to convert the image to a string (bascially the reverse of imagecreatefromstring()). Any ideas?

Posted: Thu Oct 13, 2005 9:32 pm
by feyd

Posted: Thu Oct 13, 2005 9:35 pm
by MathewByrne
Yeah not what I'm really looking for, file_get_contents takes a file and converts to a string, I already opened the file into an image resource and resized it.

I know I could save it to a temp file but I'd prefer a direct method if one exists.

Posted: Thu Oct 13, 2005 9:46 pm
by josh
Unfortunately (correct me if I'm wrong), you'll have to use output buffering.

Posted: Thu Oct 13, 2005 9:48 pm
by feyd
There is no such function. You have to output the image data via one of the output streams such as imagepng(). You can, however, capture the output via output buffering (ob_start())

Posted: Fri Oct 14, 2005 10:00 am
by pickle
The reason you can't go right from image resource to a string is because strictly speaking, the data of an image resource isn't a picture. When you call imagejpeg(), for example, GD converts the binary data of the image resource into the format of a JPEG file. If you go right from an image resource to a string, you're just gonna get a garbled mess.

Posted: Sat Oct 15, 2005 6:21 pm
by josh
but there's no reason they can't make a version of imagejpeg that returns instead of outputs...