Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image memory use #2045

Merged
merged 2 commits into from
Jun 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ 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);
}
}
Expand Down Expand Up @@ -559,6 +561,14 @@ protected function image()
return $this;
}

/**
* Frees the cached image file.
*/
protected function resetImage()
{
$this->image = null;
}

/**
* Save the image with cache.
*
Expand Down Expand Up @@ -587,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaks image handling as the image quality gets worse and worse on every resize.

return $cachedPath;
}

/**
Expand Down