-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix image memory use #2045
Conversation
Looks good! |
@@ -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); |
There was a problem hiding this comment.
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.
@tsnorri Can you please try my approach in your use case? |
@mahagr Unfortunately I had a rather tight schedule and then forgot about this. I just tested with Grav 1.5.8 and did not get any out-of-memory errors. |
Creating image derivatives currently keeps all the images in memory until the PHP interpreter is finished. With a substantial number of files or large images this can cause out of memory errors. I attempted to fix the issue by saving the image on disk immediately after the derivative has been created and then freeing it.
Processing large images still takes time. Ideally, multiple threads could be used to create the derivatives, if there is enough memory.
Please note that currently Gregwar\Image\Adapter\GD does not free the associated image resource on deallocation. I've created a pull request to fix this, too. (The checks don't pass because of a configuration error.)