-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 1.13 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bytes"
"fmt"
"image"
"io"
"io/ioutil"
"log"
"os"
"github.com/oov/resize-test/resizer"
)
func save(f resizer.StreamResizer, r io.Reader, filename string, format string, w int, h int) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
return f.StreamResize(file, r, format, w, h)
}
func main() {
imgBuf, err := ioutil.ReadFile("test.jpg")
if err != nil {
log.Fatalln(err)
}
r := bytes.NewReader(imgBuf)
cfg, _, err := image.DecodeConfig(r)
if err != nil {
log.Fatalln(err)
}
md, err := os.Create("output/README.md")
if err != nil {
log.Fatalln(err)
}
defer md.Close()
fmt.Fprintln(md, `# Image Quality Preview`)
fmt.Fprintln(md)
w, h := cfg.Width/7, cfg.Height/7
for idx, f := range resizer.AllResizer {
log.Println(f.Name(), "processing...")
r.Seek(0, os.SEEK_SET)
err := save(f, r, fmt.Sprintf("output/%02d-%s.png", idx, f.Name()), "png", w, h)
if err != nil {
log.Println(f.Name(), err)
continue
}
fmt.Fprintf(md, "### %s\n\n", f.Name())
fmt.Fprintf(md, "![%s output image](%02d-%s.png)\n\n", f.Name(), idx, f.Name())
}
}