add svg output support, but only with primitive

This commit is contained in:
Will Norris 2019-10-13 09:06:27 -07:00
parent b951a9ccc3
commit a1e81bb21f
3 changed files with 17 additions and 2 deletions

View file

@ -65,6 +65,11 @@ func Transform(img []byte, opt Options) ([]byte, error) {
format = "jpeg"
}
if opt.Format == "svg" && opt.Primitive.Count == 0 {
// svg output only supported with primitive transform
opt.Format = ""
}
if opt.Format != "" {
format = opt.Format
}
@ -109,6 +114,12 @@ func Transform(img []byte, opt Options) ([]byte, error) {
if err != nil {
return nil, err
}
case "svg":
o := opt // copy
o.Primitive.Count = 0
m = transformImage(m, o)
model := transformPrimitive(m, opt)
buf.WriteString(model.SVG())
default:
return nil, fmt.Errorf("unsupported format: %v", format)
}