Welcome Guest, Not a member yet? Register   Sign In
The Image Manipulation class and image blobs from the database...
#1

[eluser]Fabdrol[/eluser]
Hi folks!

I've got a tiny question. I've written an Google Gears based multi-file uploader. (soon I'll release it to the public, but if you're interested - drop me a line! [email protected])

The upload controller who handles the uploaded bytes saves the blob bytes one by one into a database. Well, I know there's a lot of discussion going on about saving to a database or a file system and the file system is getting the better of it, but trust me, for a lot of valid reasons I chose for a database in this project. But now, I need to manipulate the files on output. (live, thus)

Imagine three different methods in a controller, one outputting a image thumbnail, the other a 'regular' image size and the third outputting the original. Like this:

Code:
>> http://my-app.com/index.php/download/thumbnail/9611cada1e54eef43935421c1851a6da
>> http://my-app.com/index.php/download/regular/9611cada1e54eef43935421c1851a6da
>> http://my-app.com/index.php/download/original/9611cada1e54eef43935421c1851a6da

The code for the 'original' method is easy:

Code:
function original($uid) {
    $img = $this->attachments->extract($uid);
            
    header("Content-type: ".$img->mimetype);
    echo $img->filecontent;
}

But for the other two methods I'd like to use the Image lib. Is there a way? It seems that the image lib only accepts real file names, no blob strings...

I hope you can give me a hand here!

thanks!
Fabian
#2

[eluser]Cro_Crx[/eluser]
Looking through the Image Lib, you would need to hack it up in several places to use a database blob instead of an actual image file. I think this is because the underlaying graphics libraries require real image files and not image information.

It's possible to save the information to a temporary file and then process it, although it's not direct, it would achieve what you want. Other than that, it would take a bit of effort to modify the image library to take image information.
#3

[eluser]Fabdrol[/eluser]
Hi Cro_Crx,

Thanks for your reply, but I already got it worked out.
My code:

Code:
function original($uid) {
    $this->getimage($uid);
}

function thumbnail($uid) {
    $file = $this->getimage($uid);
    $this->_resizejpg($file, 100, 100);
}

function resized($uid) {
    $file = $this->getimage($uid);
    $this->_resizejpg($file, 800, 600);
}

function getimage($uid) {
    $img = $this->attachments->extract($uid);
            
    header("Content-type: ".$img->mimetype);
    echo $img->filecontent;
}

function _resizejpg($file, $width, $height) {
    // resize stuff
}




Theme © iAndrew 2016 - Forum software by © MyBB