/
image.go
54 lines (45 loc) · 1.05 KB
/
image.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
51
52
53
54
package main
import (
"image"
"image/color"
"image/png"
"io"
"github.com/kettek/apng"
)
// PNG is an object for image formated png.
type PNG struct {
name string
image image.Image
}
// Encode fills the background and writes the PNG.image to w in PNG format.
func (p *PNG) Encode(w io.Writer) error {
img := filledImage(p.image, color.White)
return png.Encode(w, img)
}
// StoreName return the file name for PNG.
func (p *PNG) StoreName() string {
return p.name + ".png"
}
// APNG is an object for image formated png.
type APNG struct {
name string
image apng.APNG
}
// Encode fills the background and writes the APNG.image to w in PNG format.
func (a *APNG) Encode(w io.Writer) error {
frames := []apng.Frame{}
for _, frame := range a.image.Frames {
out := filledImage(frame.Image, color.White)
img := frame
img.Image = out
frames = append(frames, img)
}
return apng.Encode(w, apng.APNG{
Frames: frames,
LoopCount: 0,
})
}
// StoreName return the file name for APNG.
func (a *APNG) StoreName() string {
return a.name + ".png"
}