imagejpeg内存耗尽

编程入门 行业动态 更新时间:2024-10-23 02:02:37
本文介绍了imagejpeg内存耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm creating thumbnails cycling through a lot of images, when I find a large image I get:

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

现在我已经知道如何绕过这个:

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

我想知道的是它耗尽内存的原因!是否有一些调试工具可以准确显示内存耗尽的时间?具体来说,这会告诉我是否有变量/数组会破坏我的记忆?

What I want to know is why it exhaust the memory! Is there some debug tools that will show me exactly when memory is exhausting? And specifically that will show me if there are variables/arrays that are killing my memory?

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

OR, are there better way to resize images other then:

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

非常感谢!

推荐答案

是否有一些调试工具将准确显示内存为耗尽?

Is there some debug tools that will show me exactly when memory is exhausting?

您可以使用 memory_get_usage 和 memory_get_peak_usage

具体来说,这将告诉我是否有变量/ 的数组会破坏我的记忆吗?

And specifically that will show me if there are variables/arrays that are killing my memory?

有时变量只是资源持有者,实质上指向数据结构可能是用其他语言创建的。 PHP无法衡量这些。只需在代码中的可疑行之后使用内存使用函数来缩小罪魁祸首。

Sometimes variables are just resource holders that, in essence, point to data structures that may be created in other languages. PHP cannot measure these. Just use the memory usage functions after suspect lines in your code to narrow down the culprit.

某些设置(如共享主机)会限制您修改内存要求的能力。这些限制可以在PHP,Web服务器和/或OS级别实现。您需要通过调用phpinfo()来确保您的memory_limit请求成功。

Certain setups (like shared hosting) restrict your ability to modify memory requirements. These restrictions can be implemented at the PHP, web server and/or OS level. You'll want to ensure that your memory_limit request is successful by calling phpinfo().

更多推荐

imagejpeg内存耗尽

本文发布于:2023-11-01 02:20:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存   imagejpeg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!