mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
move filters
This commit is contained in:
parent
54c156625c
commit
991e95f02e
31
internal/epub/filters/autorotate.go
Normal file
31
internal/epub/filters/autorotate.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package filters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/draw"
|
||||||
|
|
||||||
|
"github.com/disintegration/gift"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AutoRotate() *autoRotateFilter {
|
||||||
|
return &autoRotateFilter{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type autoRotateFilter struct{}
|
||||||
|
|
||||||
|
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
|
if srcBounds.Dx() > srcBounds.Dy() {
|
||||||
|
dstBounds = gift.Rotate90().Bounds(srcBounds)
|
||||||
|
} else {
|
||||||
|
dstBounds = srcBounds
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
||||||
|
if src.Bounds().Dx() > src.Bounds().Dy() {
|
||||||
|
gift.Rotate90().Draw(dst, src, options)
|
||||||
|
} else {
|
||||||
|
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package epub
|
package epub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"github.com/celogeek/go-comic-converter/internal/epub/filters"
|
||||||
"image/draw"
|
|
||||||
|
|
||||||
"github.com/disintegration/gift"
|
"github.com/disintegration/gift"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,7 +10,7 @@ func NewGift(options *ImageOptions) *gift.GIFT {
|
|||||||
g.SetParallelization(false)
|
g.SetParallelization(false)
|
||||||
|
|
||||||
if options.AutoRotate {
|
if options.AutoRotate {
|
||||||
g.Add(&autoRotateFilter{})
|
g.Add(filters.AutoRotate())
|
||||||
}
|
}
|
||||||
if options.Contrast != 0 {
|
if options.Contrast != 0 {
|
||||||
g.Add(gift.Contrast(float32(options.Contrast)))
|
g.Add(gift.Contrast(float32(options.Contrast)))
|
||||||
@ -25,22 +23,3 @@ func NewGift(options *ImageOptions) *gift.GIFT {
|
|||||||
)
|
)
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
type autoRotateFilter struct{}
|
|
||||||
|
|
||||||
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
|
||||||
if srcBounds.Dx() > srcBounds.Dy() {
|
|
||||||
dstBounds = gift.Rotate90().Bounds(srcBounds)
|
|
||||||
} else {
|
|
||||||
dstBounds = srcBounds
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
|
||||||
if src.Bounds().Dx() > src.Bounds().Dy() {
|
|
||||||
gift.Rotate90().Draw(dst, src, options)
|
|
||||||
} else {
|
|
||||||
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user