add pixel to avoid empty image

This commit is contained in:
Celogeek 2023-01-15 14:35:53 +01:00
parent 421a5ef5a7
commit 0f3d55279e
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -0,0 +1,32 @@
package filters
import (
"image"
"image/color"
"image/draw"
"github.com/disintegration/gift"
)
func Pixel() gift.Filter {
return &pixel{}
}
type pixel struct {
}
func (p *pixel) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
if srcBounds.Dx() == 0 || srcBounds.Dy() == 0 {
dstBounds = image.Rect(0, 0, 1, 1)
} else {
dstBounds = srcBounds
}
return
}
func (p *pixel) Draw(dst draw.Image, src image.Image, options *gift.Options) {
if dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1 {
dst.Set(0, 0, color.White)
}
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
}