forked from gographics/imagick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1006 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
41
42
43
44
45
46
47
48
// Port of http://members.shaw.ca/el.supremo/MagickWand/extent.htm to Go
package main
import (
"os"
"gopkg.in/gographics/imagick.v3/imagick"
)
func main() {
imagick.Initialize()
defer imagick.Terminate()
var err error
mw := imagick.NewMagickWand()
pw := imagick.NewPixelWand()
pw.SetColor("blue")
err = mw.ReadImage("logo:")
if err != nil {
panic(err)
}
w := int(mw.GetImageWidth())
h := int(mw.GetImageHeight())
mw.SetImageBackgroundColor(pw)
// This centres the original image on the new canvas.
// Note that the extent's offset is relative to the
// top left corner of the *original* image, so adding an extent
// around it means that the offset will be negative
err = mw.ExtentImage(1024, 768, -(1024-w)/2, -(768-h)/2)
if err != nil {
panic(err)
}
// Set the compression quality to 95 (high quality = low compression)
err = mw.SetImageCompressionQuality(95)
if err != nil {
panic(err)
}
mw.DisplayImage(os.Getenv("DISPLAY"))
if err != nil {
panic(err)
}
}