我还研究了其他几个类似的问题,但不幸的是,这些问题都没有解决我遇到的问题。
这就是脚本。
<?php
// returns a PNG graph from the $_GET['per'] variable
$per = imagecreate(302,7);
$background = imagecolorallocate($per, 0xFF, 0xFF, 0xFF);
$foreground = imagecolorallocate($per, 0x00, 0x8A, 0x01);
$border = imagecolorallocate($per, 0x99, 0x99, 0x99);
if ($_GET['per'] > 0)
{
$grad = imagecreatefrompng("images/grad.png");
$per2 = imagecopy($per, $grad, 1, 1, 0, 0, ($_GET['per'] * 3), 5);
imagerectangle($per, 0, 0, 301, 6, $border);
}
header("Content-type: image/png");
imagepng($per,NULL,5);
?>我已经检查了GD支持是否打开,所以我不确定是什么问题。如果我只构建一个简单的栏而不使用图像,它将工作得很好,但当我尝试使用图像构建时,它只显示一张损坏的图像的图片。
发布于 2012-11-07 08:18:47
您需要确保per存在,否则将抛出未定义的索引错误
if ($_GET['per'] > 0)应该是这样的
if (isset($_GET['per']) && $_GET['per'] > 0)或者,如果您想确保它不是空的并且存在,您可以这样做
if (!empty($_GET['per']) && $_GET['per'] > 0)因为在检查变量是否为空之前,empty()函数还会检查该变量是否存在。
https://stackoverflow.com/questions/13261366
复制相似问题