Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvnobrega's avatar

Images generated with PHP are displayed encrypted in Laravel

I created the following code to generate a simple image with PHP:

$largura = 1200;
$altura = 800;

$imagem = imagecreatetruecolor($largura, $altura);

$cor_cinza = imagecolorallocate($imagem, 192, 192, 192);

imagefilledrectangle($imagem, 0, 0, $largura, $altura, $cor_cinza);

header('Content-Type: image/png');

imagepng($imagem);

When I do this outside of Laravel the image is printed on the screen normally. But in Laravel instead of the image this appears: https://prnt.sc/BT-V_bSFizHi

Why does this happen?

The strange thing is that if I try to publish on Facebook, Facebook captures the image correctly, but when printing in the browser everything is encrypted.

Can you help me ?

0 likes
1 reply

Please or to participate in this conversation.