Uploading an old GIF image, got this error:
ValueError: imagecolorsforindex(): Argument #2 ($color) is out of range in imagecolorsforindex() (line 324 of /path/to/backdrop1/core/modules/system/image.gd.inc).
The code at that line is:
$transparent_color = imagecolorsforindex($image->resource, $transparent);
The value of $transparent turns out to be 255 for that image. Idk why that would be "out of range". Thoughts?
Comments
I did some searching and learned that this is a known problem with some GIF images. The Drupal 7 api docs show that there is additional code in
image_gd_create_tmp.inc
to check for this case and avoid the error. See:https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_create_tmp/7.x
Not sure why it's not in Backdrop ... maybe it could be added?
That function also exists in Backdrop so it might be something else going on. https://github.com/search?q=repo%3Abackdrop%2Fbackdrop%20image_gd_create...
@herb -
Perhaps I wasn't clear. The function is there in Backdrop but the code to handle the problem of this specific case is not. Specifically, the Drupal code for the function includes the following in the
if ($transparent >= 0)
condition:The Backdrop version of the function has this code instead:
There's no checking of the palette size to see whether the value returned for
$transparent
is valid. The included link to stackoverflow in the D7 code comments describes the problem in more detail.I really don't know why PHP doesn't handle this more elegantly but apparently it still doesn't. I'm running PHP 8.2.25.