Output raw image from Imagick image in PHP

WASD42 picture WASD42 · Feb 8, 2011 · Viewed 19.3k times · Source

I'm using Imagick lib to do some modifications to original image. Then I'd like to output it directly to browser without saving. Is there a way to do that?

I tried to use Imagick::writeImage('STDOUT') (empty output) and 'php://stdout' with error "Unable to write to file".

Any ideas? :)

Answer

Nabab picture Nabab · Feb 8, 2011

You just need to echo your imagick object:

$img = new Imagick($file);
header('Content-Type: image/'.$img->getImageFormat());
echo $img;