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 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起