gpt4 book ai didi

php - imagejpeg内存耗尽

转载 作者:可可西里 更新时间:2023-11-01 01:10:20 26 4
gpt4 key购买 nike

我正在创建循环浏览大量图像的缩略图,当我找到一张大图像时,我得到:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13056 bytes)

现在我已经知道如何通过以下方式规避此问题:

ini_set('memory_limit', '-1');

我想知道的是为什么会耗尽内存!是否有一些调试工具可以准确显示内存何时耗尽?特别是如果有变量/数组正在消耗我的内存,它会告诉我吗?

或者,是否有更好的调整图像大小的方法:

$thumb=imagecreatetruecolor($newwidth,$newheight); 
$source=imagecreatefromjpeg($imgfile);
imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);
imagejpeg($thumb,$destinationfile,85);

?

非常感谢!

最佳答案

您可能需要调用 imagedestroy()一旦你完成了每张图片(即 $source$thumb),尤其是当你正在处理大量图片时。我不确定PHP的垃圾收集是否会清除GD图像资源。

关于php - imagejpeg内存耗尽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2668533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com