-
Notifications
You must be signed in to change notification settings - Fork 11
/
hello.go
60 lines (51 loc) · 1.16 KB
/
hello.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
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ingore
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
tiff "github.com/chai2010/tiff"
)
var files = []string{
"./testdata/BigTIFFSamples/BigTIFFSubIFD8.tif",
"./testdata/multipage/multipage-gopher.tif",
}
func main() {
for _, name := range files {
// Load file data
f, err := os.Open(name)
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Decode tiff
m, errors, err := tiff.DecodeAll(f)
if err != nil {
log.Println(err)
}
// Encode tiff
for i := 0; i < len(m); i++ {
for j := 0; j < len(m[i]); j++ {
newname := fmt.Sprintf("%s-%02d-%02d.tiff", filepath.Base(name), i, j)
if errors[i][j] != nil {
log.Printf("%s: %v\n", newname, err)
continue
}
var buf bytes.Buffer
if err = tiff.Encode(&buf, m[i][j], nil); err != nil {
log.Fatal(err)
}
if err = ioutil.WriteFile(newname, buf.Bytes(), 0666); err != nil {
log.Fatal(err)
}
fmt.Printf("Save %s ok\n", newname)
}
}
}
}