user1425322
user1425322

Reputation: 159

Draw image in PHP and no image being displayed

Folks,I've some 288 points with their X,Y co-ordinates and a value assigned to them. I need to show this figuratively. I tried gd and imagettftext but simple code to draw a blank image isn't working even when I've installed and configured gd.

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

$image = imagecreatetruecolor(400, 300);

// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);

// Draw the polygon
imagepolygon($image, array(
        0,   0,
        100, 200,
        300, 200
    ),
    3,
    $col_poly);

// Output the picture to the browser
header('Content-type: image/png');

imagepng($image);
imagedestroy($image);

The output in the browser is no image

Upvotes: 0

Views: 997

Answers (2)

vyevdokimov
vyevdokimov

Reputation: 21

Try to set encoding of php file with your code to UTF-8 without BOM (e.g. in Notepad++).

enter image description here

Upvotes: 2

Hanky Panky
Hanky Panky

Reputation: 46900

Your code works right and image shows. Most probably your GD library is not working as expected. Try this

$image = imagecreatetruecolor(400, 300) or die('Cannot Initialize new GD image stream');

Upvotes: 0

Related Questions