forked from cshum/imagor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (40 loc) · 1 KB
/
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
package main
import (
"github.com/ario-eth/imagor/vips"
"net/http"
"os"
)
func main() {
// manipulate images using libvips C bindings
vips.Startup(nil)
defer vips.Shutdown()
// create source from io.ReadCloser
resp, err := http.Get("https://raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif")
if err != nil {
panic(err)
}
source := vips.NewSource(resp.Body)
defer source.Close() // source needs to remain available during the lifetime of image
params := vips.NewImportParams()
params.NumPages.Set(-1) // enable animation
image, err := source.LoadImage(params) // load image from source
if err != nil {
panic(err)
}
defer image.Close()
if err = image.ExtractArea(30, 40, 50, 70); err != nil {
panic(err)
}
if err = image.Flatten(&vips.Color{
R: 0, G: 255, B: 255,
}); err != nil {
panic(err)
}
buf, err := image.ExportGIF(nil)
if err != nil {
panic(err)
}
if err = os.WriteFile("dancing-banana.gif", buf, 0666); err != nil {
panic(err)
}
}