From f9e82708ba2981466daa70347d9f8378801c532a Mon Sep 17 00:00:00 2001 From: tsnorri Date: Thu, 31 May 2018 16:42:45 +0300 Subject: [PATCH 1/2] Add a method for freeing the image file, free each derivative after it has been created --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 05bc4c486c..beab621d20 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -301,6 +301,7 @@ public function derivatives($min_width, $max_width = 2500, $step = 200) { $derivative->set('width', $width); $derivative->set('height', $height); + $derivative->resetImage(); $this->addAlternative($ratio, $derivative); } } @@ -558,6 +559,14 @@ protected function image() return $this; } + + /** + * Frees the cached image file. + */ + protected function resetImage() + { + $this->image = null; + } /** * Save the image with cache. From 9050e3b0e22e490fd24cf48fa8c84aadba5207c5 Mon Sep 17 00:00:00 2001 From: tsnorri Date: Thu, 31 May 2018 17:46:40 +0300 Subject: [PATCH 2/2] Save the scaled derivative on disk before freeing it, store its path --- system/src/Grav/Common/Page/Medium/ImageMedium.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index beab621d20..8be914e12c 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -301,6 +301,7 @@ public function derivatives($min_width, $max_width = 2500, $step = 200) { $derivative->set('width', $width); $derivative->set('height', $height); + $derivative->saveImage(); $derivative->resetImage(); $this->addAlternative($ratio, $derivative); } @@ -559,7 +560,7 @@ protected function image() return $this; } - + /** * Frees the cached image file. */ @@ -596,7 +597,9 @@ protected function saveImage() $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; } /**