diff --git a/src/claviska/SimpleImage.php b/src/claviska/SimpleImage.php index 703c599..75a1826 100644 --- a/src/claviska/SimpleImage.php +++ b/src/claviska/SimpleImage.php @@ -2337,18 +2337,24 @@ public static function normalizeColor(string|array $color): array $hex = strval(preg_replace('/^#/', '', $color)); // Support short and standard hex codes - if (strlen($hex) === 3) { + if (strlen($hex) === 3 || strlen($hex) === 4) { [$red, $green, $blue] = [ $hex[0].$hex[0], $hex[1].$hex[1], $hex[2].$hex[2], ]; - } elseif (strlen($hex) === 6) { + if (strlen($hex) === 4) { + $alpha = hexdec($hex[3]) / 255; + } + } elseif (strlen($hex) === 6 || strlen($hex) === 8) { [$red, $green, $blue] = [ $hex[0].$hex[1], $hex[2].$hex[3], $hex[4].$hex[5], ]; + if (strlen($hex) === 8) { + $alpha = hexdec($hex[6].$hex[7]) / 255; + } } else { throw new Exception("Invalid color value: $color", self::ERR_INVALID_COLOR); }