thephpleague / color-extractor

Extract colors from an image like a human would do.
thephpleague.com
MIT License
1.3k stars 159 forks source link

question: is over 1gb of memory usage normal? #66

Closed samthomson closed 2 years ago

samthomson commented 3 years ago

php memory limit is 1024 MB, the below exception occurs while processing a 12 MB jpeg. I can of course increase the memory limit, but wondered if this level of memory usage is expected?

PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/auto/vendor/league/color-extractor/src/League/ColorExtractor/ColorExtractor.php on line 226
PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/auto/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122

Here's my color extraction code:

$primaryPalette = Palette::fromFilename($sFullPath);
$extractor = new ColorExtractor($primaryPalette);
$primaryPalette = null;

$aExtractedColours = $extractor->extract(5);
$extractor = null;
MatTheCat commented 2 years ago

Yeah unfortunately the algorithm is pretty naive so this memory consuption is normal 😕

samthomson commented 2 years ago

Thanks for confirming, and for making this super useful module :) I updated my memory limit substantially and that indeed solved it. I will just keep in mind I need to have such an amount of memory available for this.

MatTheCat commented 2 years ago

And thank you for your understanding 🙏