From dbe580bfc701c4c171f1552b4f3bdc5ad9107cf7 Mon Sep 17 00:00:00 2001 From: Piotr Wieczorek Date: Sun, 15 Mar 2020 11:21:24 +0100 Subject: [PATCH] Add Image copy method --- tk/image.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tk/image.go b/tk/image.go index c99d1b3..fdd339f 100644 --- a/tk/image.go +++ b/tk/image.go @@ -174,3 +174,69 @@ func parserImageResult(id string, err error) *Image { } return &Image{id, photo, nil} } + +func (i *Image) Copy(source *Image, attributes ...*ImageCopyAttr) { + var attrList []string + for _, attr := range attributes { + if attr == nil { + continue + } + if s, ok := attr.value.(string); ok { + if s != "" { + pname := "atk_tmp_" + attr.key + setObjText(pname, s) + attrList = append(attrList, fmt.Sprintf("-%v $%v", attr.key, pname)) + } else { + attrList = append(attrList, fmt.Sprintf("-%v", attr.key)) + } + continue + } + attrList = append(attrList, fmt.Sprintf("-%v {%v}", attr.key, attr.value)) + } + eval(fmt.Sprintf("%v copy %v %s", i.id, source.id, strings.Join(attrList, " "))) +} + +type ImageCopyAttr struct { + key string + value interface{} +} + + +func ImageCopyAttrFrom(x1, y1, x2, y2 int) *ImageCopyAttr { + return &ImageCopyAttr{fmt.Sprintf("from %d %d %d %d", x1, y1, x2, y2), ""} +} + +func ImageCopyAttrTo(x1, y1, x2, y2 int) *ImageCopyAttr { + return &ImageCopyAttr{fmt.Sprintf("%d %d %d %d", x1, y1, x2, y2), ""} +} + +func ImageCopyAttrShrink() *ImageCopyAttr { + return &ImageCopyAttr{"shrink", ""} +} + +func ImageCopyAttrZoom(x, y int) *ImageCopyAttr { + return &ImageCopyAttr{fmt.Sprintf("zoom %d %d", x, y), ""} +} + +func ImageCopyAttrSubSample(x, y float64) *ImageCopyAttr { + return &ImageCopyAttr{fmt.Sprintf("subsample %f %f", x, y), ""} +} + +type CompositingRule int + +const ( + CompositingRuleOverlay = iota + CompositingRuleSet +) +var ( + compositingRuleName = []string{"overlay", "set"} +) +func (v CompositingRule) String() string { + if v > 0 && int(v) < len(compositingRuleName) { + return compositingRuleName[v] + } + return "" +} +func ImageCopyAttrCompositingRule(rule CompositingRule) *ImageCopyAttr { + return &ImageCopyAttr{"compositingrule", rule} +}