mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
add pixel to avoid empty image
This commit is contained in:
parent
421a5ef5a7
commit
0f3d55279e
32
internal/epub/filters/pixel.go
Normal file
32
internal/epub/filters/pixel.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user