Created
December 20, 2017 17:13
-
-
Save ConradIrwin/df2d5374f3bc38ba0dc14d13692ed8dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/binary" | |
| "fmt" | |
| "io/ioutil" | |
| "os" | |
| ) | |
| const pngHeader = "\x89PNG\r\n\x1a\n" | |
| func main() { | |
| buffer, err := ioutil.ReadAll(os.Stdin) | |
| if err != nil { | |
| panic(err) | |
| } | |
| if string(buffer[0:len(pngHeader)]) != pngHeader { | |
| panic("invalid png") | |
| } | |
| buffer = buffer[len(pngHeader):] | |
| for len(buffer) > 0 { | |
| length := binary.BigEndian.Uint32(buffer[:4]) | |
| tag := buffer[4:8] | |
| fmt.Println(string(tag), length) | |
| if string(tag) == "pHYs" { | |
| data := buffer[8 : length+8] | |
| fmt.Println("pHYs", binary.BigEndian.Uint32(data[:4]), binary.BigEndian.Uint32(data[4:8]), uint(data[8])) | |
| } | |
| buffer = buffer[length+12:] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment