Fix image memory use (#2045)

* Add a method for freeing the image file, free each derivative after it has been created

* Save the scaled derivative on disk before freeing it, store its path
This commit is contained in:
Tuukka Norri
2018-06-09 00:33:40 +03:00
committed by Andy Miller
parent 3b4296c7a4
commit da7a93527d

View File

@@ -301,6 +301,8 @@ class ImageMedium extends Medium
$derivative->set('width', $width);
$derivative->set('height', $height);
$derivative->saveImage();
$derivative->resetImage();
$this->addAlternative($ratio, $derivative);
}
}
@@ -559,6 +561,14 @@ class ImageMedium extends Medium
return $this;
}
/**
* Frees the cached image file.
*/
protected function resetImage()
{
$this->image = null;
}
/**
* Save the image with cache.
*
@@ -587,7 +597,9 @@ class ImageMedium extends Medium
$this->image->merge(ImageFile::open($overlay));
}
return $this->image->cacheFile($this->format, $this->quality);
$cachedPath = $this->image->cacheFile($this->format, $this->quality);
$this->set('filepath', $cachedPath);
return $cachedPath;
}
/**