-1

this is the code

<?php
  $x = imagecreatetruecolor(250, 250);
  $y = imagecolorallocate($x, 120 ,156,100);
  header('Content-Type: image/jpeg');
  imagejpeg($x);
?>

It is giving output as The image "http://localhost/firstprogram.php" cannot be displayed because it contains errors.

I also tried Example from https://www.php.net/manual/en/function.imagerectangle.php and it still displayed the same message.

And also can someone tell if header is necessary or not and what exactly is it used for?

Alexander
  • 80
  • 1
  • 10
Amateur
  • 21
  • 4

1 Answers1

0

you made a image, you allocate it, but you did not draw it. try this code

<?php
 $x = imagecreatetruecolor(250, 250);
 $y = imagecolorallocate($x, 120 ,156,100);
 imagerectangle($x, 50, 50, 150, 150, $y);// draw the rectange of image
 header('Content-Type: image/jpeg');
 imagejpeg($x);
?>
ajay chawla
  • 63
  • 1
  • 11