Computer Science Canada

Load image to GD2 from MySQL BLOB

Author:  Amailer [ Tue Apr 21, 2009 7:05 pm ]
Post subject:  Load image to GD2 from MySQL BLOB

Hey,
Say I have a blob data of an image (JPEG) in a database. I want to know how I can pull that data and load it into GD2 (like imagecreatefromjpeg) so I can manipulate it and re-draw the image with php.

Thanks!

Author:  md [ Tue Apr 21, 2009 9:23 pm ]
Post subject:  RE:Load image to GD2 from MySQL BLOB

store it in the DB encoded somehow, say base64; then fetch it into a string, decode it, and then make the image.

Alas I do not know specifics of the library, but I know there is a way.

Author:  Dan [ Tue Apr 21, 2009 9:54 pm ]
Post subject:  RE:Load image to GD2 from MySQL BLOB

I have allwasy been aginsted sotring images and binnary files in databases like that. Is there any reason you need to store it in the database and can't use the file system witch was made for such things?

Author:  Amailer [ Sat Apr 25, 2009 1:51 am ]
Post subject:  RE:Load image to GD2 from MySQL BLOB

Yeah I just ended up storing it as a file... I had figured managing the editing of the image would have been easier, say if I want to edit the original image, or revert back it would be better to have all the data in the database.

However, to get it to be "editable" in GD2, I had to basically re-create the image in PHP (separate page) and then call it back in my image editor page. At least that's the only way I could think of.

Author:  Tony [ Sat Apr 25, 2009 1:57 am ]
Post subject:  Re: RE:Load image to GD2 from MySQL BLOB

Amailer @ Sat Apr 25, 2009 1:51 am wrote:
in PHP (separate page)

You know, PHP doesn't have to be embedded into a page.

Author:  Amailer [ Sat Apr 25, 2009 2:06 am ]
Post subject:  RE:Load image to GD2 from MySQL BLOB

Are you referring to PHP GTK? (what? confused...and scared now).

What I meant though, the only other way I could think of was recreating the image from the database as a .jpg/.png or whatever file and then using imagecreatefromjpeg to call it from the URL.

Author:  jeffgreco13 [ Mon Apr 27, 2009 9:02 am ]
Post subject:  RE:Load image to GD2 from MySQL BLOB

what kind of editing are you trying to do? just resizing and cropping? or colour changes and filters too


: