php - 允许的内存大小为 134217728 字节耗尽(尝试分配 18472 字节)

标签 php memory

我在这一行得到了上面的错误:

imagefill($canvas, 0, 0, imagecolorallocate($canvas, 255, 255, 255));

该脚本适用于所有图像类型,但它会在分辨率大于 4000 x 3000 像素的图像上崩溃。图片本身只有 500kb。 这是所有代码:

$canvas = imagecreatetruecolor(imagesx($source), imagesy($source));
imagefill($canvas, 0, 0, imagecolorallocate($canvas, 255, 255, 255));
imagealphablending($canvas, TRUE);
imagecopy($canvas, $source, 0, 0, 0, 0, imagesx($source), imagesy($source));
imagedestroy($source);
$quality = 100; // 0 = worst / smaller file, 100 = better / bigger file 
imagejpeg($canvas, $strPath.$p_Id.".jpg", $quality);        //----- save image
ImageDestroy($canvas);

最佳答案

无论压缩图像的大小是多少,您的库似乎都需要更多内存。我看到您正在使用 128 mb atm,将其增加到 256,方法是:

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

关于php - 允许的内存大小为 134217728 字节耗尽(尝试分配 18472 字节),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26037836/

相关文章:

c - 当我 malloc 错误的内存量时,为什么 C 不会崩溃

c - C中的字符串起始状态

php - 调用未定义的方法 MongoDB\Driver\Cursor::current()

javascript - 如何获取输入值到php var

php - mySQL 数据库字段 PHP 中的 Textarea 为空

mysql - 限制 MySQL 用户的 CPU/内存使用

C++:我可以使用指针超出应用程序内存的范围吗?

node.js - 消耗所有可用内存的 Node 脚本

php - 值未插入表中

PHP 应用程序状态