imagecolorsforindex(): Argument #2 ($color) is out of range when running bin/magento catalog:images:resize

By | March 26, 2024
Spread the love

This issue related to GD library with some images. Recently upgraded from 2.4.4 to 2.4.5. While placing the images in pub/media folder and running bin/magento catalog:images:resize, then getting the following error

imagecolorsforindex(): Argument #2 ($color) is out of range#0 /var/www/html/vendor/magento/framework/Image/Adapter/Gd2.php(347): imagecolorsforindex(Object(GdImage), 48)

It seems PHP GD Library gives error if Color went out of range https://www.php.net/manual/en/function.imagecolorsforindex.php.

so index 48 is out of range, in previous version this returned false but now it throws error. I had checked the view.xml, but still can’t figure out the issue.

Solution:

vendor/magento/framework/Image/Adapter/Gd2.php around line 346:

-        if ($transparentIndex >= 0 && $transparentIndex <= imagecolorstotal($this->_imageHandler)) {
+        if ($transparentIndex >= 0 && $transparentIndex < imagecolorstotal($this->_imageHandler)) {