I found the reason and also the solution for my problem. The reason is simple enough: the draw.Draw method checks if the image has an alpha channel and applies the composite operation as described in the article above. For me the alpha channel for both end of the gradient image has been set to 255. When I changed this value to 0 it worked as expected.
On Monday, May 9, 2022 at 10:03:21 AM UTC+3 Endre Simo wrote: > I was trying to create a gradient overlay mask as it is on image/draw > package (https://go.dev/blog/image-draw#geometric-alignment) having the > end result exactly as on the result of the sample image. What I would like > more exactly is to gradiently fade out the source image used as a mask over > the destination image. Unfortunately this is not happening. I was searching > through the internet for examples but didn't found anything relevant. I was > also looking into the core package `DrawMask` method, but this also didn't > led to any success. I'm pasting the code here for more clarity. > > unionMask := image.NewNRGBA(image.Rect(0, 0, scale, scale)) > // Add to union mask > ellipse := ellipse.NewEllipse(row, col, int(float64(scale)*0.8/1.6), > int(float64(scale)*0.8/2.2)) > draw.Draw(unionMask, unionMask.Bounds(), ellipse, image.Point{X: row - > scale/2, Y: col - scale/2}, draw.Over) > > // Converts the buffer array to an image. > img := c.pixToImage(imgData, scale) > > // Create a new image and draw the webcam frame captures into it. > newImg := image.NewNRGBA(image.Rect(0, 0, scale, scale)) > draw.Draw(newImg, newImg.Bounds(), img, newImg.Bounds().Min, draw.Over) > > // Apply the blur effect over the obtained pixel data converted to image. > blurred, err := c.blurFace(newImg, scale) > if err != nil { > return err > } > faceTemplate := image.NewNRGBA(image.Rect(0, 0, scale, scale)) > draw.Draw(faceTemplate, img.Bounds(), blurred, image.Point{}, draw.Over) > > // Draw the triangled image through the facemask and on top of the source. > draw.DrawMask(img.(draw.Image), img.Bounds(), blurred, image.Point{}, > unionMask, image.Point{}, draw.Over) > > Since a picture worth a thousand of words, in the image below I would like > the blurred image mask to be smoothen out towards the edges. > > [image: Screen Shot 2022-05-09 at 9.54.39 AM.png] > > And here is the gradient mask: > > [image: Screen Shot 2022-05-09 at 10.00.10 AM.png] > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3cbdc537-1c3f-45fe-80fe-d5829b4701dcn%40googlegroups.com.