关于gd类库中的imagecreate()解决方法
时间:2021-07-01 10:21:17
帮助过:39人阅读
关于gd类库中的imagecreate()
代码如下:
//header("content-type: image/png");
include("config.php");
$s1 = "SELECT * FROM question WHERE t=0";
$result = mysql_query($s1);
$i = 0;
while($row=mysql_fetch_array($result))
{
$id = $row["id"];
$content0 = $row["content"];
$s2 = "SELECT * FROM question WHERE t='$id' ";
$result1 = mysql_query($s2);
echo "
";
echo "".$content0." |
";
while($rows=mysql_fetch_array($result1))
{
$content = $rows["content"];
$num = $rows["num"] * 10;
$im = imagecreate($num,20);
$black = imagecolorallocate($im,rand(0,254),rand(0,255),rand(0,255));
$name = $i;
imagepng($im,"E:\apache\htdocs\image\$name.png");
echo "".$content." | ";
echo " | ";
echo "".($num/10)." |
";
imagedestroy($im);
$i ++;
}
echo "
";
}
?>
发现把imagecreate放在循环里 总是会出错Warning: imagecreate() [function.imagecreate]: Invalid image dimensions
而且输出的图片都是一张图片 是什么原因呢
------解决方案-------------------- Warning: imagecreate() [function.imagecreate]: Invalid image dimensions : 无效的图片尺寸
说明 $num = $rows["num"] * 10; 这儿的 $rows["num"]可能是个空字符串值。至于为什么是空值,就看你的表设计了
------解决方案--------------------被你忽悠了
echo "
 | ";
只能得到
 | 这样的结果!
你需要
echo "
 | ";
才能得到
 |  |  |