Issues

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

Description

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");
        imagepng($png);
        imagedestroy($png);
    }

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

Errors remains by adding:


$this->setNoRender(true);
$this->getView()->layout()->disableLayout();

and replacing :


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

by


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

Comments

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.