tags:

views:

524

answers:

2

My problem is rather straight-forward:

  1. Retrieve an image from a MySQL database (currently stored as binary data in a blob column)
  2. Rotate that image 90 degrees (using PHP's imagerotate)
  3. Store the image back in the database with that rotation changes applied.

I'm having trouble finding functions that will let me save the image as a datastream (not to the file system) since these images are not allowed to touch the web server (hence, why they are in the db). Any advice is welcome.

Thanks

A: 

Are you converting the image to another type before rotating? You said you're using tiffs, GD can only read the headers of tiff images, you'll need to convert it first. Probably with ImageMagick

Most likely you will want to save the files to a temp directory:

  • Query database for file
  • Save to temp directory (you can protect the files by setting permissions if necessary)
  • Rotate image
  • Insert back into database
  • Delete temp file
jjclarkson
*sigh*After doing more digging, I've realized I do need to use imagick. Unfortunately, I do not have access to this library on my current environment and won't likely be getting access anytime soon.Thanks for all your help, though.
Levi Hackwith
A: 

SELECT the data from your DB. Pass the data into imagecreatefromstring

You will now have an image resource that you can call imagerotate on.

To save it back to the DB you will need to output it using imagepng / imagejpeg or the equivalent function for the image type you're using. These functions output to browser or file so you can use output buffering to capture a string to save back to the DB.

ob_start();
imagepng($resource);
$img_data = ob_get_contents();
ob_end_clean();

$img_data can now be saved to the DB.

This is only a rough outline but I hope I've explained the idea.

Neil Aitken
Please not I havent tried this, but it's the best method I can think of that doesnt involve a temp file.The output buffering may mess up the image data so you'll have to test it out.
Neil Aitken
This looks like a sound idea, but I get a warning when I try to pass blob data to imagecreatefromstring: "Data is not in a recognized format"
Levi Hackwith
I dont think GD supports TIFF, didnt see that in your question initially. You may need to use an external library like imagemagick.I'm pretty sure this idea would work for png / jpeg but I'm not too familiar with TIFF
Neil Aitken