Forum Moderators: coopster

Message Too Old, No Replies

how do I get a SQL blob, and turn it into an Imagick obj?

         

httpwebwitch

1:16 am on Nov 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a bunch of JPG images in my database as SQL blobs.
I'd like to perform Imagick actions on them, like resizing and rotating.

I know how to SELECT the blob from my SQL database.
But how do I create an Imagick object out of the data?
All the Imagick methods I see load their contents from a file.

[php.net...]

httpwebwitch

1:38 am on Nov 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wicked. I found it

[quote]$query = "SELECT photoblob FROM photos WHERE id = ".$id;
$result = mysql_query($query);
$sqlrow = mysql_fetch_array($result);

$image = new Imagick();
$image->[red]readImageBlob[/red]($sqlrow['photoblob']);[/quote]

rocknbil

7:23 pm on Nov 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You usually do. :-)

Just curious, what are your reasons for storing image data in the database? Isn't there more chance of image corruption?

httpwebwitch

1:09 am on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> more chance of image corruption?

how so?

I chose database because it's easy, images are easily read/written, they stay associated with their row ID (which contains other info too). And I don't have to keep track of file names or deal with File I/O, naming conventions. At a max size of 500px with thumbs at 120x120 and 40x40, the blobs aren't very big.

There are likely just as many reasons not to do it that way. Scalability is a concern. Some day I might want to keep my blobs in a storage cloud instead of in my relational db. Some day.

Also, this way I don't need to worry about a malicious user-uploaded "image" finding its way onto my web server, with whatever viruses or malware hitching a ride, security is tighter, simpler, less loopholes and potential (or imagined) vulnerabilities.

But I do know that I never again want to build a site that hosts 100,000 little JPG files on the server. FTP upload, download, backup & syncing are annoyingly slow when you have to wait 8 hours for all your images to move from one machine to another.

rocknbil

3:49 am on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what I've been told by a few administrators and seen a few instances of, but I imagine it's just as easy to corrupt a file on disk - seen that too. I'd also learned that images increase the DB file size drastically (obviously.) Truthfully, I've just never played with it much, but then, I stayed out of the street as a kid because my mama tole' me I'd get run over by a car. :-)

One of those things I've absorbed and forgot why.

httpwebwitch

2:25 am on Nov 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to get a good, thorough pile of pros and cons about storing images as blobs. But I'm going to post it as a question in a new thread. Thanks rocknbil!