From da7a93527de84f050262f58e1bfaea5aa449c116 Mon Sep 17 00:00:00 2001 From: Tuukka Norri Date: Sat, 9 Jun 2018 00:33:40 +0300 Subject: [PATCH] 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 --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 05bc4c486..8be914e12 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -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; } /**