1

The code suppose show the image like this below enter image description here

however the result is this below

enter image description here

this is my code here

simplegraph.php

<?php
// set up image canvas
$height = 200;
$width = 200;
$im = imagecreatetruecolor(width, height)($width, $height);
$white = imagecolorallocate ($im, 255, 255, 255);
$blue = imagecolorallocate ($im, 0, 0, 255);

// draw on image
imagefill($im, 0, 0, $blue);
imageline($im, 0, 0, $width, $height, $white);
imagestring($im, 4, 50, 150, 'Sales', $white);

// output image
header('Content-type: image/png');
imagepng ($im);

// clean up
imagedestroy($im);
?>

here is all files in

htdocs

enter image description here

lin Joe
  • 82
  • 1
  • 9
  • I suppose show the image that I show above, but it did not – lin Joe Feb 13 '18 at 09:08
  • For the future, it's best to [get errors to display](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) when debugging – apokryfos Feb 13 '18 at 09:14

1 Answers1

3

This is probably because of this statement:

$im = imagecreatetruecolor(width, height)($width, $height);

The above is incorrect syntax. Change this to:

$im = imagecreatetruecolor($width, $height);

The image will show after this, because PHP is assuming, that width and height are constants, but they do not exist and it will give out error, and after that the ($width, $height) part will cause the syntax error. But that is the part that you actually need.

mega6382
  • 9,211
  • 17
  • 48
  • 69