Magento 2 – imagecolorsforindex() Argument Out of Range Error

bin-magentoimage resizemagento2product-imagesupgrade

I 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, I am 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)

Any idea what went wrong and how to rectify it ?

enter image description here

edit :
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.

Best Answer

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

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