Inserting modified image into a database

See all posts See thread Reply

Re: Inserting modified image into a database new!
by colin, 15 years, 9 months ago
Yes, my mistake... If you use imagejpeg(), you need to have a PHP image resource as an argument. What the class returns is actually the content of the picture (in JPEG, or in PNG, depending on your settings when calling process()), and not a PHP ressource.

So to dump the image on file, you need to do something like this:
$img = $foo->process();
$file = fopen('my_picture.jpg', "wb");
fwrite($file, $img); 
fclose($file);

I don't have time to test but I reckon that is the issue. My apologies for the wrong code in my previous posts.

Note that instead of writing the image content to a file, you could output it to the browser. In this case again, it is not a PHP image resource that you output, but the actual content of the image in JPG:
$img = $foo->process();
header("Content-type: image/jpeg");
echo $img;

Looking at the code of the class again, I should probably modify it so that you can have direct access to the image resource if you wish to pass it though imagejpeg() yourself.Reply