views:

107

answers:

2

I'm trying to use Imagemagick (actually PHP's Imagick) to create and output (serve) an image without saving it to disk first.

Currently I'm having to save the file and then use verot upload class to serve the image.

I'm hoping there's something simple that I'm missing.

Any suggestions/advice will be much appreciated.

(Apache 2 server, PHP5)

A: 

I admit to never having used Imagick, but just looking at the examples, echoing the image should work just fine:

header('Content-type: image/jpeg');

$image = new Imagick('image.jpg');

echo $image;
deceze
+3  A: 

Sure. This should work for you:

$image = new Imagick();
// Do your image creation stuff. Make sure to set $image->setImageFormat();

header('Content-Type: image/filetype'); // Change filetype
echo $image;
Mark Trapp
Huh, I really was missing something simple!I've now also seen people echoing $image->getImageBlob();Is there any difference?
jezmck
jezmeck: not really; Imagick::__toString() uses getImageBlob(). I think the reason you might see that from time to time is because the Imagick class didn't implement __toString() until 2.0.0-b1, which requires PHP 5.1.3.
Mark Trapp
Cool, many thanks.
jezmck