XF 2.2 explanation of color multipliers


Well-known member
default avatars do not meet ADA contrast ratios in many color combinations.

can someone help me decipher these multipliers?

where does 12.92 come from? .7152 ?

public static function getRelativeLuminance($r, $g = null, $b = null)
        if (is_array($r))
            $b = $r[2];
            $g = $r[1];
            $r = $r[0];

        $scaler = function($color)
            $color /= 255;
            if ($color <= 0.03928)
                return $color / 12.92;
                return pow(($color + 0.055) / 1.055, 2.4);

        $r = $scaler($r);
        $g = $scaler($g);
        $b = $scaler($b);

        return 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
I've played with this off and on for a few months now and cannot obtain reliable contrast results with any of the settings i've tried.

I still don't understand the multiplier factors. Can anyone shed some light here? I'm ready to disable all avatars for guests.
You are likely getting a false positive because of the way default avatars is implemented (CSS background color vs image); the color contrast they talk about is for content and headings.

Incidental: Text or images of text that are part of an inactive user interface component, that are pure decoration, that are not visible to anyone, or that are part of a picture that contains significant other visual content, have no contrast requirement.

Think is the applicable clause in the WCAG guidelines. In general, avatars generally end up getting set at some point (or ignored if they're not) so it really serves no purpose to accessibility.

In the XF1 style I did I actually removed avatars by default, with the option to turn on more unique accessible images (custom add-on by a developer who no longer does XF addons). For screen readers, avatars are extra noise so it serves no purpose to the blind/partially blind, and people with color sensitivity could choose whether or not to enable the avatars; there was also a toggle to remove contrast.
Top Bottom