[Solved] php ImageCreate [closed]


You are outputting the string hello world, and then outputting the image. This will result in corrupted image data, because it will have 11 bytes at the start of it that make no sense in the context of an image.

Remove the print('hello world'); line, and it should output a valid image – But your page will not contain the text hello world, you’ll need to output a proper HTML page with the text on and point the src attribute of an img tag to the PHP script that generates the image if you want that to work.

For example:

page.html

<html>
  <head>
    <title>My Page</title>
  </head>
  <body>
    hello world<br>
    <img src="https://stackoverflow.com/questions/11863144/image.php" />
  </body>
</html>

image.php

<?php

$im = ImageCreate(200,200);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,150,150,$black);
header('Content-Type: image/png');
ImagePNG($im);

?>

1

solved php ImageCreate [closed]