记忆之外的图像干预——拉拉威尔



内存问题:非常规图像处理

我使用laravel的干预图像类,并将图像复制、调整大小和编码到sites目录。本质上是模拟上传到虚假列表。

然而,在运行数据库种子时,我似乎遇到了内存问题。

错误消息:

local.ERROR: exception 'SymfonyComponentDebugExceptionFatalErrorException' 
with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 5056 bytes)' 
in C:xampphtdocsequezonevendorinterventionimagesrcInterventionImageGdDecoder.php:115

每张图片不超过1265x625。只有当图像大于1300x700时,才会调整图像大小。因此,实际上没有调整图像大小。。。

Gd\解码器.php的第115行

$canvas = imagecreatetruecolor($width, $height);

imagecreatetruecolor似乎扩展了php的gd类。

这是我的代码的基础:

$image = Image::make(( ! is_string($file))? $file->getRealPath(): $file);
if ($image->width() > self::MAX_IMAGE_WIDTH || $image->height() > self::MAX_IMAGE_HEIGHT) {
    self::resizeImage($image, self::MAX_IMAGE_WIDTH, self::MAX_IMAGE_HEIGHT);
}
/*
Some code here to retrieve the listing from the database, 
create an image in the database
assign image to the listing
*/
$image->encode('jpg',100);
$image->save($img->getImageLocation(), 100);

我弄清楚了内存泄漏的来源。

在内存崩溃之前,种子将种子化大约8-14个列表。上传大约60-70张图片。然后它的内存用完了。列表是随机生成的,图像被随机分配给列表。。。

这完全把我难住了。如果你想了解更多信息,请告诉我。

完成后,尝试使用destroy释放为实例分配的内存:

$image->encode('jpg',100);
$image->save($img->getImageLocation(), 100);
$image->destroy();

http://image.intervention.io/api/destroy

最新更新