-
Notifications
You must be signed in to change notification settings - Fork 185
/
main.go
50 lines (39 loc) · 992 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
49
50
// Port of http://members.shaw.ca/el.supremo/MagickWand/resize.htm to Go
package main
import (
"fmt"
"gopkg.in/gographics/imagick.v2/imagick"
)
func main() {
imagick.Initialize()
// Schedule cleanup
defer imagick.Terminate()
var err error
mw := imagick.NewMagickWand()
err = mw.ReadImage("logo:")
if err != nil {
panic(err)
}
// Get original logo size
width := mw.GetImageWidth()
height := mw.GetImageHeight()
// Calculate half the size
hWidth := uint(width / 2)
hHeight := uint(height / 2)
// Resize the image using the Lanczos filter
// The blur factor is a float, where > 1 is blurry, < 1 is sharp
err = mw.ResizeImage(hWidth, hHeight, imagick.FILTER_LANCZOS, 1)
if err != nil {
panic(err)
}
// Set the compression quality to 95 (high quality = low compression)
err = mw.SetImageCompressionQuality(95)
if err != nil {
panic(err)
}
out := "/tmp/out.png"
if err = mw.WriteImage(out); err != nil {
panic(err)
}
fmt.Printf("Wrote: %s\n", out)
}