I use zend framework 2 and try to return an created with gd2 library jpeg image . but it doesn't work. could you look my code what's the problem? My code is run with plain php in normally but in zf2 problem?
class PictureController extends AbstractActionController
{
public function colorPaletteAction(){
....
....
//canvas created at above.
imagejpeg($canvas);
imagedestroy($canvas);
$response = $this->getResponse();
return $response->getHeaders()->addHeaderLine('Content-Type', 'image/jpeg');
}
}
You set the Content-Type header to 'image/png' instead of 'image/jpeg'.
Also try adding the content-transfer-encoding and content-length headers:
I also don't see you adding the actual content to the response:
where $yourJpegContent contains the binary image data.
imagejpeg
outputs the data immediately which you don't want to do. You can either use the output buffer to capture this data or write it to a file first. The output buffer is probably easiest:If this doesn't work, temporarily comment out the Content-Type header line to see what output you're getting. Make sure there aren't any errors or HTML in the output.