【发布时间】:2014-04-14 08:53:24
【问题描述】:
我在网上看到一个教程,他们声称下面的代码制作了一个饼图。然而,当我运行这个确切的代码时,我有错误 Fatal error: Call to undefined function imagecolorsallocate() in /**/**/*/piechart.php on line 7(我使用 asterix 来覆盖我的文件夹名称)。有什么建议?或者有没有其他方法可以在不使用第三方材料的情况下创建一个。
<?php
//create image
$image = imagecreatetruecolor(100,100);
//allocate some colour
$white = imagecolorsallocate($image, 0xFF , 0xFF, 0xFF);
$gray = imagecolorsallocate($image, 0xC0 , 0xC0, 0xC0);
$darkgray = imagecolorsallocate($image, 0x90 , 0x90, 0x90);
$navy = imagecolorsallocate($image, 0x00 , 0x00, 0x80);
$darknavy = imagecolorsallocate($image, 0x00 , 0x00, 0x05);
$red = imagecolorsallocate($image, 0xFF , 0x00, 0x00);
$darkred = imagecolorsallocate($image, 0x90, 0x00, 0x00);
//make the 3d effect
for($i = 60; $i >50; $i--){
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 45, 75, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 75, 360, $darkred, IMG_ARC_PIE);
}
imagefilledarc($image ,50 ,50 , 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image ,50 ,50 , 100, 50, 45, 75, $gray, IMG_ARC_PIE);
imagefilledarc($image ,50 ,50 , 100, 50, 75, 360, $red, IMG_ARC_PIE);
//flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
谢谢
【问题讨论】:
-
imagecolorsallocate!==imagecolorallocate -
您是否在 PHP 配置中启用了 GD 扩展?
-
@Class 感谢愚蠢的错误无法发现!您刚刚为我节省了数小时的研究时间