func makeCircleSmooth(src image.Image, factor float64) image.Image {
d := src.Bounds().Dx()
if src.Bounds().Dy() < d {
d = src.Bounds().Dy()
}
dst := imaging.CropCenter(src, d, d)
r := float64(d) / 2
for x := 0; x < d; x++ {
for y := 0; y < d; y++ {
xf := float64(x)
yf := float64(y)
delta := math.Sqrt((xf-r)*(xf-r)+(yf-r)*(yf-r)) + factor - r
switch {
case delta > factor:
dst.Set(x, y, color.Transparent)
case delta > 0:
m := 1 - delta/factor
c := dst.NRGBAAt(x, y)
c.A = uint8(float64(c.A) * m)
dst.Set(x, y, c)
}
}
}
return dst
}
The background (PNG)
The final result:
I've tried with different pictures and I still got the same result
I'm trying to crop a image as a circle (https://github.com/disintegration/imaging/issues/72) and apply a
color.Transparent
, but the image is getting awhite
borderThe background (PNG)
The final result:
I've tried with different pictures and I still got the same result