2020-05-10 07:11:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
2020-05-10 15:40:56 +00:00
|
|
|
|
|
|
|
"opslag.de/schobers/tins2020/img"
|
2020-05-10 07:11:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setAlpha(path string, alpha int) error {
|
2020-05-10 15:40:56 +00:00
|
|
|
src, err := img.DecodeImage(path)
|
2020-05-10 07:11:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
bounds := src.Bounds()
|
|
|
|
dst := image.NewNRGBA(bounds)
|
|
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
|
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
|
|
|
c := color.NRGBAModel.Convert(src.At(x, y)).(color.NRGBA)
|
|
|
|
if c.A > 0 {
|
|
|
|
c.A = uint8(alpha)
|
|
|
|
}
|
|
|
|
dst.Set(x, y, c)
|
|
|
|
}
|
|
|
|
}
|
2020-05-10 15:40:56 +00:00
|
|
|
return img.EncodePNG(path, dst)
|
2020-05-10 07:11:08 +00:00
|
|
|
}
|