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

Conversation

tsnorri
Copy link
Contributor

@tsnorri tsnorri commented May 31, 2018

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.)

@rhukster
Copy link
Member

rhukster commented Jun 8, 2018

Looks good!

@rhukster rhukster merged commit da7a935 into getgrav:develop Jun 8, 2018
@@ -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.

mahagr added a commit that referenced this pull request Jun 15, 2018
@mahagr
Copy link
Member

mahagr commented Jun 15, 2018

@tsnorri Can you please try my approach in your use case?

@tsnorri
Copy link
Contributor Author

tsnorri commented Mar 1, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants