【问题标题】:PHP - imagecreatetruecolor - allowed memory size of exhaustedPHP - imagecreatetruecolor - 允许的内存大小耗尽
【发布时间】:2013-08-27 12:40:40
【问题描述】:

我需要将这些图像合二为一。为此,我执行以下操作:

  1. 创建具有正确尺寸的空白图像

    $full_image = imagecreate($full_width, $full_height);

  2. 将png图片一张一张复制到空白图片上

    imagecopy($full_image, $src, $dest_x, $dest_y, 0, 0, $src_width, $src_height)

但是,有些图像会变得非常大,例如:imagecreatetruecolor(8832, 3955);,我得到Allowed memory size of 134217728 bytes exhausted (tried to allocate 8832 bytes)

我想知道是否有一种方法可以将图像放在一起,而不会将整个图像存储在内存中。在生成图像时,可能会以一定的时间间隔将图像数据写入磁盘。

【问题讨论】:

    标签: php io


    【解决方案1】:

    首先:当你完成一个资源或一个大数组等时,使用 unset($resource);将其标记为“准备好”进行垃圾回收。

    其次,图像处理非常密集。您可以考虑使用 Gearman 之类的东西,它基本上允许您将密集的进程分流到队列中。

    第三,你也可以试试这个:

    ini_set('memory_limit', '256M');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-25
      • 2018-08-04
      • 1970-01-01
      • 2017-12-13
      • 2019-04-25
      • 2010-10-20
      • 2013-10-21
      • 1970-01-01
      相关资源
      最近更新 更多