doudi8519 2012-10-18 03:18 采纳率: 100%
浏览 58
已采纳

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

I have a PHP script that creates a very tall image and draws a lot of lines on it (an organizational web kind of look). For the tallest images I've tried creating, the line drawing just stops abruptly toward the middle to bottom of the image: http://i.imgur.com/4Plgr.png

I ran into this problem using imagecreate(), then I found out that imagecreatetruecolor() can handle larger images, so I switched to that. I'm still having the same problem, but the script can now handle somewhat larger images. I think it should be drawing about 1200 lines. The script doesn't take more than 3 seconds to execute. Here's an image that executed completely: http://i.imgur.com/PaXrs.png

I adjusted the memory limits with ini_set('memory_limit', '1000M') but my scripts never reach near the limit.

How do I force the script to keep drawing until it finishes? Or how can I use PHP to create an image using less memory (which I think is the problem)?

if(sizeof($array[0])<300)
$image=imagecreate($width,$height);
else
$image=imagecreatetruecolor($width,$height);
imagefill($image,0,0,imagecolorallocate($image,255,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,$posx1,$posy1,$posx2,$posy2){
$black=imagecolorallocate($image,0,0,0);
if($posy1==$posy2)
imageline($image,$posx1,$posy1,$posx2,$posy2,$black);
else{
imageline($image,$posx1,$posy1,$posx1+89,$posy1,$black);
imageline($image,$posx1+89,$posy1,$posx1+89,$posy2,$black);
imageline($image,$posx1+89,$posy2,$posx2,$posy2,$black);
}
return $image;
}
  • 写回答

2条回答 默认 最新

  • dpl3350 2012-10-18 04:19
    关注

    OP here. I figured out, or at least got around, my problem. I was drawing a lot of lines on the image, and the way my code got those points created a lot of repeats, so I still suspect it was a memory problem. I consolidated all the points, taking out the repeats and now it works just fine. Thanks to anyone that tried to help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置