Skip to content

Fix image memory use#2045

Merged
rhukster merged 2 commits intogetgrav:developfrom
tsnorri:fix-image-memory-use
Jun 8, 2018
Merged

Fix image memory use#2045
rhukster merged 2 commits intogetgrav:developfrom
tsnorri:fix-image-memory-use

Conversation

@tsnorri
Copy link
Copy Markdown
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
Copy Markdown
Member

rhukster commented Jun 8, 2018

Looks good!

@rhukster rhukster merged commit da7a935 into getgrav:develop Jun 8, 2018

return $this->image->cacheFile($this->format, $this->quality);
$cachedPath = $this->image->cacheFile($this->format, $this->quality);
$this->set('filepath', $cachedPath);
Copy link
Copy Markdown
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 pushed a commit that referenced this pull request Jun 15, 2018
@mahagr
Copy link
Copy Markdown
Member

mahagr commented Jun 15, 2018

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

@tsnorri
Copy link
Copy Markdown
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