Opacity returns an image which blends the two input images by the percentage provided. Percent must be of range 0 <= percent <= 1.0
(bg image.Image, fg image.Image, percent float64)
| 284 | // Opacity returns an image which blends the two input images by the percentage provided. |
| 285 | // Percent must be of range 0 <= percent <= 1.0 |
| 286 | func Opacity(bg image.Image, fg image.Image, percent float64) *image.RGBA { |
| 287 | percent = f64.Clamp(percent, 0, 1.0) |
| 288 | |
| 289 | dst := Blend(bg, fg, func(c0, c1 fcolor.RGBAF64) fcolor.RGBAF64 { |
| 290 | r := c1.R*percent + (1-percent)*c0.R |
| 291 | g := c1.G*percent + (1-percent)*c0.G |
| 292 | b := c1.B*percent + (1-percent)*c0.B |
| 293 | |
| 294 | c2 := fcolor.RGBAF64{R: r, G: g, B: b, A: c1.A} |
| 295 | return alphaComp(c0, c2) |
| 296 | }) |
| 297 | |
| 298 | return dst |
| 299 | } |
| 300 | |
| 301 | // Darken combines the foreground and background images by picking the darkest value per channel |
| 302 | // for each pixel. The result is then returned. |