├── .gitignore ├── LICENSE ├── README.md ├── cmd └── diff-image │ └── main.go ├── diff.go ├── example.png ├── test.sh └── testdata └── 1 ├── after.png ├── before.png └── diff.png /.gitignore: -------------------------------------------------------------------------------- 1 | /tmp 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Naoki YAGUCHI 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-diff-image 2 | 3 | A diff tool for images. 4 | 5 | ## Installation 6 | ``` 7 | $ go get -u github.com/murooka/go-diff-image/... 8 | ``` 9 | 10 | ## Usage 11 | ```bash 12 | diff-image -o=diff.png before.png after.png 13 | # open diff.png 14 | ``` 15 | ## Example 16 | 17 | ![example](https://raw.githubusercontent.com/murooka/go-diff-image/master/example.png) 18 | -------------------------------------------------------------------------------- /cmd/diff-image/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "image" 7 | "image/png" 8 | "log" 9 | "os" 10 | 11 | diffimage "github.com/murooka/go-diff-image" 12 | ) 13 | 14 | func mustOpen(filename string) *os.File { 15 | f, err := os.Open(filename) 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | 20 | return f 21 | } 22 | 23 | func mustLoadImage(filename string) image.Image { 24 | f := mustOpen(filename) 25 | defer f.Close() 26 | 27 | img, _, err := image.Decode(f) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | 32 | return img 33 | } 34 | 35 | func mustSaveImage(img image.Image, output string) { 36 | f, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE, 0644) 37 | defer f.Close() 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | 42 | png.Encode(f, img) 43 | } 44 | 45 | func rate16(c uint32, r float64) uint16 { 46 | fc := float64(c) 47 | return uint16(65535 - (65535-fc)*r) 48 | } 49 | 50 | func main() { 51 | var ( 52 | output string 53 | ) 54 | flag.StringVar(&output, "output", "diff.png", "output filename") 55 | flag.StringVar(&output, "o", "diff.png", "output filename") 56 | flag.Parse() 57 | args := flag.Args() 58 | if len(args) != 2 { 59 | fmt.Println("usage: imagediff [