ZF2-158: Impossible to show image generated by imagepng / imagejpeg functions


Hi there, The following code works fine with zf1.11 but not in zf2:

public function indexAction()   
        $png = imagecreatetruecolor(800, 600);
        imagesavealpha($png, true);
        $trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
        imagefill($png, 0, 0, $trans_colour);
        $Yellow = imagecolorallocate($png, 255, 255, 0);
        imagefilledellipse($png, 650, 150, 200, 200, $Yellow );
        header("Content-type: image/png");

zf1.11 => display yellow circle zf2 => display "L'image ne peut être affichée car elle contient des erreurs"

Errors remains by adding:


and replacing :

header("Content-type: image/png");


$headers = $this->response->headers();
$headers->addHeaderLine('Content-Type', 'image/jpeg');


Code tags added.

Hi David,

Can you still reproduce this with the latest code?

I've tried your code snippet in Rob Allen's tutorial and it worked fine for me.