douguan8940 2012-08-08 21:50
浏览 33

用PHP绘制图像,不显示图像

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

  • 写回答

2条回答 默认 最新

  • dsjklb0205 2012-08-08 21:56
    关注

    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');
    
    评论

报告相同问题?