initial commit
This commit is contained in:
commit
c578765961
18 changed files with 1862 additions and 0 deletions
48
convert.go
Normal file
48
convert.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/image/tiff"
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
"os"
|
||||
)
|
||||
|
||||
func convert(i image.Image) image.Image {
|
||||
rect := i.Bounds()
|
||||
n := image.NewGray(rect)
|
||||
for x := 0; x < rect.Max.X; x++ {
|
||||
for y := 0; y < rect.Max.Y; y++ {
|
||||
p := color.GrayModel.Convert(i.At(x, y)).(color.Gray)
|
||||
if p.Y <= 130 {
|
||||
n.Set(x, y, p)
|
||||
} else {
|
||||
n.Set(x, y, color.White)
|
||||
}
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func main() {
|
||||
in, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
out, err := os.OpenFile(os.Args[2], os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
i, _, err := image.Decode(in)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = tiff.Encode(out, convert(i), &tiff.Options{tiff.Uncompressed, false})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue