public static function mix($color1, $color2, $weight) 
    {
        if ($weight < 0) {
            $weight = 0;
        } elseif ($weight > 1) {
            $weight = 1;
        }
        
        $a = ($color1 & 0xff) * (1 - $weight) + ($color2 & 0xff) * $weight;
        if ($a <= 0.1) {
            return 0;
        }
        
        $r = (
            ($color1 >> 24) * ($color1 & 0xff) * (1 - $weight) +
            ($color2 >> 24) * ($color2 & 0xff) * $weight
            ) / $a;
            
        $g = (
            (($color1 >> 16) & 0xff) * ($color1 & 0xff) * (1 - $weight) +
            (($color2 >> 16) & 0xff) * ($color2 & 0xff) * $weight
            ) / $a;
            
        $b = (
            (($color1 >> 8) & 0xff) * ($color1 & 0xff) * (1 - $weight) +
            (($color2 >> 8) & 0xff) * ($color2 & 0xff) * $weight
            ) / $a;
        
        if ($a > 255) $a = 255;    
        if ($r > 255) $r = 255;
        if ($g > 255) $g = 255;
        if ($b > 255) $b = 255;
        
        return ((int)$r << 24) | ((int)$g << 16) | ((int)$b << 8) | (int)$a;
    }