Browse Source

Add Add color.RGB.String() and Add color.RGB.MarshalJSON()

DarthSim 1 week ago
parent
commit
e3170af889
1 changed files with 9 additions and 1 deletions
  1. 9 1
      vips/color/color.go

+ 9 - 1
vips/color/color.go

@@ -34,6 +34,14 @@ func RGBFromHex(hexcolor string) (RGB, error) {
 	return c, nil
 }
 
+func (c RGB) String() string {
+	return fmt.Sprintf("#%02x%02x%02x", c.R, c.G, c.B)
+}
+
+func (c RGB) MarshalJSON() ([]byte, error) {
+	return []byte(fmt.Sprintf(`"#%02x%02x%02x"`, c.R, c.G, c.B)), nil
+}
+
 func (c RGB) LogValue() slog.Value {
-	return slog.StringValue(fmt.Sprintf("#%02x%02x%02x", c.R, c.G, c.B))
+	return slog.StringValue(c.String())
 }