浏览代码

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

DarthSim 1 周之前
父节点
当前提交
e3170af889
共有 1 个文件被更改,包括 9 次插入1 次删除
  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())
 }