在非常高的图像上使用PHP绘制线条,脚本停止绘制.怎么了,怎么解决?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了在非常高的图像上使用PHP绘制线条,脚本停止绘制.怎么了,怎么解决?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 PHP脚本,可以创建一个非常高的图像,并在其上绘制很多行(组织Web外观).对于我尝试创建的最高图像,线条图突然停止向图像的中间到底部http://i.imgur.com/4Plgr.png

我使用imagecreate()遇到了这个问题,然后我发现imagecreatetruecolor()可以处理更大的图像,所以我切换到了.我仍然遇到同样的问题,但脚本现在可以处理更大的图像.我认为它应该绘制大约1200行.该脚本执行时间不超过3秒.这是一张完全执行的图像:http://i.imgur.com/PaXrs.png

我使用ini_set(‘memory_limIT’,’1000M’)调整了内存限制,但我的脚本从未达到接近极限.

如何强制脚本继续绘制直到完成?或者我如何使用PHP来创建使用更少内存的图像(我认为这是问题)?

if(sizeof($array[0])<300)
$image=imagecreate($width,$height);
else
$image=imagecreatetruecolor($width,$height);
imagefill($image,imagecolorallocate($image,255,255));
for($p=0; $p<sizeof($linepoints); $p++){
$pOSX1=77+177*$linepoints[$p][0];
$posy1=-4+46*$linepoints[$p][1];
$posx2=77+177*$linepoints[$p][2];
$posy2=-4+46*$linepoints[$p][3];
$image=draw_trail($image,$posx1,$posy1,$posx2,$posy2);
}
imagepng($image,"images/table_backgrounds/table_background".$tsn.".png",9);
imagedestroy($image);

function draw_trail($image,$posy2){
$black=imagecolorallocate($image,0);
if($posy1==$posy2)
imageline($image,$posy2,$black);
else{
imageline($image,$posx1+89,$black);
imageline($image,$black);
}
return $image;
}

解决方法

我猜你已经创建了一个内存泄漏,当你在更大的图像上做更多的操作时,你最终会达到PHP的内存限制.而不是提高限制,最好找到泄漏.

尝试更改代码,以便显式释放您在draw_trail中创建的颜色.此外,由于您传递资,因此没有理由返回$image.

if(sizeof($array[0])&amp;lt;300)
$image=imagecreate($width,255));
for($p=0; $p&lt;sizeof($linepoints); $p++)
{
    $posx1=77+177*$linepoints[$p][0];
    $posy1=-4+46*$linepoints[$p][1];
    $posx2=77+177*$linepoints[$p][2];
    $posy2=-4+46*$linepoints[$p][3];
    draw_trail($image,$posy2)
{
    $black=imagecolorallocate($image,0);
    if($posy1==$posy2)
    imageline($image,$black);
    else
    {
        imageline($image,$black);
        imageline($image,$black);
    }
    imagecolordeallocate($black);
}

脚本宝典总结

以上是脚本宝典为你收集整理的在非常高的图像上使用PHP绘制线条,脚本停止绘制.怎么了,怎么解决?全部内容,希望文章能够帮你解决在非常高的图像上使用PHP绘制线条,脚本停止绘制.怎么了,怎么解决?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。