forked from gographics/imagick
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
40 lines (31 loc) · 1001 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Port of http://members.shaw.ca/el.supremo/MagickWand/clipmask.htm to Go
package main
import (
"gopkg.in/gographics/imagick.v3/imagick"
)
func main() {
imagick.Initialize()
defer imagick.Terminate()
dest := imagick.NewMagickWand()
src := imagick.NewMagickWand()
mask := imagick.NewMagickWand()
dest.SetSize(100, 100)
src.SetSize(100, 100)
if err := dest.ReadImage("tile:tile_water.jpg"); err != nil {
panic(err)
}
if err := mask.ReadImage("mask_bite.png"); err != nil {
panic(err)
}
// When you create a mask, you use white for those parts that you want
// to show through and black for those which must not show through.
// But internally it's the opposite so the mask must be negated
mask.NegateImage(false)
dest.SetImageClipMask(mask)
if err := src.ReadImage("tile:tile_disks.jpg"); err != nil {
panic(err)
}
// This does the src (overlay) over the dest (background)
dest.CompositeImage(src, imagick.COMPOSITE_OP_OVER, 0, 0)
dest.WriteImage("clip_out.jpg")
}