Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created November 8, 2020 06:47
Show Gist options
  • Save romanitalian/b197531da5f32870e15f33a040078961 to your computer and use it in GitHub Desktop.
Save romanitalian/b197531da5f32870e15f33a040078961 to your computer and use it in GitHub Desktop.
import (
"bytes"
"image"
"image/color"
"image/draw"
"image/jpeg"
...
)
buf := new(bytes.Buffer)
m := image.NewRGBA(image.Rect(0, 0, 16, 16))
clr := color.RGBA{B: 0, A: 0}
draw.Draw(m, m.Bounds(), image.NewUniform(clr), image.ZP, draw.Src)
jpeg.Encode(buffer, img, nil)
w.Header().Set("Content-Type", "image/jpeg")
w.Header().Set("Content-Length", strconv.Itoa(len(buffer.Bytes())))
w.Write(buf.Bytes())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment