I get the following error after uploading to 3.57 - imagecolorsforindex(): Argument #2 ($color) is out of range in lib/image_functions.php on line 152.
4 posts by 3 authors in: Forums > CMS Builder
Last Post: February 20, 2023 (RSS)
I just upgraded a system to 3.57 (I know, I'm a little late to the party). After doing so, I went to upload a logo for them that was in GIF format. After selecting the file and clicking on Upload, I received the following error:
imagecolorsforindex(): Argument #2 ($color) is out of range in /home/folder/public_html/cmsAdmin/lib/image_functions.php on line 152.
Rather than trying to diagose the issue, I simply saved it as a JPG and the upload was fine. I have to say, we have not had a gif in years, so I'm not sure if it just started happening or not. It could be mere coincidence.
I just wanted to report it in case there was something anyone know about it.
We are using PHP 8.1 on this site.
By Dave - February 13, 2023
Hi Gary,
Thanks for the report. It looks like this is a new issue introduced by PHP 8:
From: https://www.php.net/manual/en/function.imagecolorsforindex.php
imagecolorsforindex() now throws a ValueError exception if color is out of range; previously, false was returned instead.
If you still have that GIF available could you email it to me at dave@interactivetools.com? We'll try to reproduce the issue and add some code to workaround it.
Thanks!
interactivetools.com
By Lucia - February 20, 2023
Hi Gary,
I've found a fix for this bug, which should be included in the next CMSB release version. If you'd like to patch it in the meantime, you can replace this line in cmsb/lib/image_functions.php (at/around line 152)
$transparentColor = @imagecolorsforindex($sourceImage, $transparentIndex);
With this:
$transparentColor = false;
if ($transparentIndex >= 0) {
$transparentColor = @imagecolorsforindex($sourceImage, $transparentIndex);
}
Let me know if you have any further questions!
Thanks,
Technical Lead
interactivetools.com