plugin.go 425 B

123456789101112131415161718192021
  1. package main
  2. import (
  3. "image"
  4. "image/color"
  5. )
  6. // Convert to binary image
  7. func Transform(src image.Image) image.Image {
  8. bounds := src.Bounds()
  9. w, h := bounds.Max.X, bounds.Max.Y
  10. ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
  11. for x := 0; x < w; x++ {
  12. for y := 0; y < h; y++ {
  13. r, _, _, _ := src.At(x, y).RGBA()
  14. ret.Set(x, y, color.RGBA{uint8(r / 255), 0, 0, 0})
  15. }
  16. }
  17. return ret
  18. }