Error with command catalog:images:resize

If you noticed that your images have not appeared on your Magento2 site you can check the log file. There you can see the error below

imagecolorsforindex(): Argument #2 ($color) is out of range#0

/vendor/magento/framework/Image/Adapter/Gd2.php(347): imagecolorsforindex()

This error happens because the PHP library GD2 for PHP 8.1 has a bug. 

For fixing this issue you should run the command below

bin/magento config:set dev/image/default_adapter IMAGEMAGICK