From a46d144fedd5c6bf45edf91805e1ac72f4848b12 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sat, 20 Feb 2016 15:42:36 -0500 Subject: [PATCH] support alpha in SetHexColor --- context.go | 4 ++-- util.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index 247d6b4..6ba4120 100644 --- a/context.go +++ b/context.go @@ -141,8 +141,8 @@ func (dc *Context) SetColor(c color.Color) { } func (dc *Context) SetHexColor(x string) { - r, g, b := parseHexColor(x) - dc.SetRGB255(r, g, b) + r, g, b, a := parseHexColor(x) + dc.SetRGBA255(r, g, b, a) } func (dc *Context) SetRGBA255(r, g, b, a int) { diff --git a/util.go b/util.go index 8d340fa..3cd3258 100644 --- a/util.go +++ b/util.go @@ -48,8 +48,9 @@ func imageToRGBA(src image.Image) *image.RGBA { return dst } -func parseHexColor(x string) (r, g, b int) { +func parseHexColor(x string) (r, g, b, a int) { x = strings.TrimPrefix(x, "#") + a = 255 if len(x) == 3 { format := "%1x%1x%1x" fmt.Sscanf(x, format, &r, &g, &b) @@ -61,6 +62,10 @@ func parseHexColor(x string) (r, g, b int) { format := "%02x%02x%02x" fmt.Sscanf(x, format, &r, &g, &b) } + if len(x) == 8 { + format := "%02x%02x%02x%02x" + fmt.Sscanf(x, format, &r, &g, &b, &a) + } return }