-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample_test.go
36 lines (29 loc) · 930 Bytes
/
example_test.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
package imgconv_test
import (
"fmt"
"io"
"log"
"github.com/sunshineplan/imgconv"
)
func Example() {
// Open a test image.
src, err := imgconv.Open("testdata/video-001.png")
if err != nil {
log.Fatalf("failed to open image: %v", err)
}
// Resize the image to width = 200px preserving the aspect ratio.
mark := imgconv.Resize(src, &imgconv.ResizeOption{Width: 200})
// Add random watermark set opacity = 128.
dst := imgconv.Watermark(src, &imgconv.WatermarkOption{Mark: mark, Opacity: 128, Random: true})
// Write the resulting image as TIFF.
if err := imgconv.Write(io.Discard, dst, &imgconv.FormatOption{Format: imgconv.TIFF}); err != nil {
log.Fatalf("failed to write image: %v", err)
}
// Split the image into 3 parts horizontally.
imgs, err := imgconv.Split(src, 3, imgconv.SplitHorizontalMode)
if err != nil {
log.Fatalf("failed to split image: %v", err)
}
fmt.Print(len(imgs))
// output:3
}