-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imagecolorsforindex(): Argument #2 ($color) is out of range #1299
Comments
@ryancramerdesign Yes, looks good to me! |
@adrianbj @ryancramerdesign, I'm still seeing this issue — do you think this should be reopened, or should I open a new issue instead? One GIF that I can reproduce this with is the first one from https://processwire.com/modules/repeater-easy-sort/. Trying to add this to an image field results in
Edit: in this case the original value for $transparentIndex is 255, and the ternary used here turns it to 254. When I check the return value of imagecolorstotal($image) it's also 254. Everything seems to work if I use Edit 2: quick glance at the issue linked above from wintercms seems to suggest that this indeed requires a more involved fix. Or, alternatively, we should use something along the lines of |
The weird thing with that image is that $color is set to Sorry, I just saw your edit where you noted it was converted to |
More info here: https://stackoverflow.com/a/3898007/1524576 |
Ok, I should read before I respond :) - we are already using |
Not well tested, but this (basically copying the logic from the Drupal patch) works for me:
|
Ok, I did a little more testing and I think this is actually what we need:
This works with the animated gif in @teppokoivula's example and it also works with gifs where a transparent color has been set. The only thing I am confused about is why the thumbnail version of the image isn't actually transparent - is this a bug, or intended behavior? In other words, why does that function proceed to do an |
@ryancramerdesign — sorry for the ping, but would be great if this issue could get some attention. I've not tested this properly, but the fix provided by @adrianbj above at least allows me to upload GIFs on my sites. |
@teppokoivula @adrianbj I've pushed a fix for this based on Adrian's suggestion. It seems to be working here with any GIFs I test with (also including the one mentioned earlier). But I am not very up-to-speed on the details of GD, Horst is really the expert so I'm CCing him here @horst-n . Please let me know if you find any issues. Thanks. |
@matjazpotocnik - I haven't tested, but it looks like Ryan's change matches my fix (slightly improved) so should be fine. I guess my only remaining question might be around the lack of transparency of the thumbnail that I noted in my last post above. But I suppose that is different to this issue anyway so we can probably close this. |
Ok, then I'll close this one. You can reopen as needed. |
Short description of the issue
PHP 8 has changed the behavior of the shutup operator - it no longer silences fatal errors. This means that some old code in ImageSizerEngineGD.php (https://github.com/processwire/processwire/blob/d8945198f4a6a60dab23bd0462e8a6285369dcb9/wire/core/ImageSizerEngineGD.php#L865) now fails with the above error.
Expected behavior
We shouldn't be relying on the shutup operator in the first place :)
Actual behavior
You can test it with this image:
Optional: Suggestion for a possible fix
Replace the above line (865) with this:
which ensures the
$transparentIndex
is not greater or equal to the total number of colors in the image.You can read more about it here: https://stackoverflow.com/questions/3874533/what-could-cause-a-color-index-out-of-range-error-for-imagecolorsforindex
Steps to reproduce the issue
Setup/Environment
Server Details
Server Settings
GD Settings
Module Details
The text was updated successfully, but these errors were encountered: