Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created August 30, 2014 22:20
Show Gist options
  • Save pokutuna/dd44e15fbfb72a786e3a to your computer and use it in GitHub Desktop.
Save pokutuna/dd44e15fbfb72a786e3a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"io/ioutil"
"os"
)
func main() {
rect := image.Rectangle{image.Pt(0, 0), image.Pt(1, 1)}
img := image.NewRGBA(rect)
img.Set(0, 0, color.Black)
file, _ := ioutil.TempFile(os.TempDir(), "image_test")
defer file.Close()
png.Encode(file, img)
fmt.Println(png.Decode(file)) // => <nil> unexpected EOF
file.Seek(0, 0)
fmt.Println(png.Decode(file)) // => &{[0 0 0 255] 4 (0,0)-(1,1)} <nil>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment