Skip to content

Instantly share code, notes, and snippets.

@mh-cbon
Last active November 4, 2016 15:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mh-cbon/2bd43c72938e2522a0188f13f7eb854e to your computer and use it in GitHub Desktop.
// data url decoding to png
package main
import (
"fmt"
"bytes"
"github.com/vincent-petithory/dataurl"
"image/png"
)
var b64 string = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAct0lEQVRogW2ZZ3xVZda39zlJKCmn7312Ob3X9ISmdERERx11bMzIzNgbOJZRLCiKtNC72BWldxFSCKGGklBDSyAJRQc7IJACXs+HzDvleZ8P/9+9P65rrbX/6157CzNEKzOtFmaJEtNFkUmymZdSUpmXnccYm5Ux5iw+6hFn01/jjDEYeMdg4Iub8hhrNvJlcZBJRhOjMjN402BgotHMeJOZyWYzJSYLk8wmJplNTE5YWXVTPssH5DGycyfqHnqQ9bf1YFX/fKZZrEwxm5lmsTLVbGGq1cYToohBp6Nf1668ZrPymtHA60YDn9yUw6y8AK8bTbxlNvH5zQUIc0WRmVYrs0SReZLETEnksbQ0XpFFPILAy3YTk1w2XjUb2fGnGOsDLsrDHraE3dRF/DQnonybneTrQICXTGbeMRqZaDRSYjIxwWSixGxh9aBCPrutF9MCHl4yZLDxD/msGJrPnKDKVLuFErOZKWbLvyAmWyxMsViYYrbyhMWKSRDo7xJ5v38eo81G3jAZmVsUYrTFhDDHZmO2aGOuKDJbtDHPJjJTFJkiSSy4Mcyie6NUZIcZlZrCY3qBHQ9EOBoLczgaoDLgoDKosS3s4lQywflkghMF+UyymHjDkEWJ2cJUs4Vpkomnu3Rm77AHmapZeTvYmTWDi1k9pIiVg/OZHVQpsVgYb7VSYsqkxGJkqsVKicXI8qEFzApqrLylgGcsRiyCQDwzi+ctJub3SSCMN1uZJ0nMlUSm3HILc+wSs0WRuZLIwuwgK1Urq+9VGZmqZ61soykeo/6hHKpDHjb4VMoDTj6V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YrLtWVcObCJqwcqOb9hGWURLyseu5srR3Zy5Ug1rXXbWT58KBv+/ji/7i/l8oFNXD2wiV93r6NfJJfX9Hp8SpiXO3fiK7+PmaZ09ocUdvtEagf0oSTLgCPQA0egB0qgGLcaQQn0RA32QPlfUMIcu8RUSWa+IjPKkElVzM2lQ9tpObabtpMHuXq0mquHttJWs4krByq5eriKlrrtXKnbztWj1ax+4gHKH/09R+eP4/KRbVw5up3LdVtZ/+JDXNq3kWNffcqVQ5VcPbiZKwc2ceVAORdqyhhitHGfIDBc0LPKLbPKK1ET1uhrsBPUQhSmm4k5YvwxmoMa7IYa7NEBEOyBFvi3/gcxBLFwnMkCvQAAAABJRU5ErkJggg==`
func main () {
dataURL, err := dataurl.DecodeString(b64)
if err!=nil {
panic(err)
}
var b bytes.Buffer
b.Write(dataURL.Data)
config, err := png.DecodeConfig(&b)
if err!=nil {
fmt.Println(err)
} else {
fmt.Println("Got config")
fmt.Printf("%#v\n", config)
}
b.Truncate(0)
b.Write(dataURL.Data)
img, err := png.Decode(&b)
if err!=nil {
fmt.Println(err)
} else {
fmt.Println("Got image")
fmt.Printf("%#v\n", img)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment