I'm trying to generate an image using php-gd but the output is only special characters. Did I use the "header('Content-Type: image/png')" correct?
My Image Class:
public function __construct(){
header('Content-Type: image/png');
$this->image = imagecreate(200, 80);
imagecolorallocate($this->image, 150, 150, 150);
$textColor = imagecolorallocate($this->image, 255,255,255);
imagestring($this->image, 28, 50, 55,rand(1000,9999), $textColor);
}
public function generateImage(){
imagepng($this->image);
imagedestroy($this->image);
}
My DefaultController:
/**
* @Route("/display-scorepng", name="scorepng")
*/
public function displayScorePng(){
$test = new ImageController;
return new Response("<h1>Hello World</h1> <br /><img src='" .$test->generateImage(). "' />");
}
Thank you for your reply..