protected static function strToColor($im, $color)
    {
        $color = ltrim($color, '#');
        
        if (strpos($color, ',') !== false) {
            list($red, $green, $blue, $opacity) = explode(',', $color) + [3 => null];
        } else {
            $red = hexdec(substr($color, 0, 2));
            $green = hexdec(substr($color, 2, 2));
            $blue = hexdec(substr($color, 4, 2));
            $opacity = 1;
        }
        
        $alpha = round((1 - $opacity) * 127);
        return imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
    }