Skip to content

Instantly share code, notes, and snippets.

@empr
Created November 30, 2012 11:37
Show Gist options
  • Save empr/4175284 to your computer and use it in GitHub Desktop.
Save empr/4175284 to your computer and use it in GitHub Desktop.
Basic image sample in Go
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
var width = 256
var height = 256
func main() {
img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
img.Set(x, y, color.RGBA{uint8(x), uint8(y), uint8((x + y) / 2), 255})
}
}
f, e := os.OpenFile("sample.png", os.O_WRONLY | os.O_CREATE, 0666)
if e != nil {
fmt.Println(e)
return
}
defer f.Close()
png.Encode(f, img)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment