mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
auto rotate if src width > src height
This commit is contained in:
parent
d0d9af7f9b
commit
b268521494
@ -7,29 +7,15 @@ import (
|
|||||||
"github.com/disintegration/gift"
|
"github.com/disintegration/gift"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AutoRotate(viewWidth, viewHeight int) gift.Filter {
|
func AutoRotate() gift.Filter {
|
||||||
return &autoRotateFilter{
|
return &autoRotateFilter{}
|
||||||
viewWidth, viewHeight,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type autoRotateFilter struct {
|
type autoRotateFilter struct {
|
||||||
viewWidth, viewHeight int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *autoRotateFilter) needRotate(srcBounds image.Rectangle) bool {
|
|
||||||
width, height := srcBounds.Dx(), srcBounds.Dy()
|
|
||||||
if width <= height {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if width <= p.viewWidth && height <= p.viewHeight {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
|
||||||
if p.needRotate(srcBounds) {
|
if srcBounds.Dx() > srcBounds.Dy() {
|
||||||
dstBounds = gift.Rotate90().Bounds(srcBounds)
|
dstBounds = gift.Rotate90().Bounds(srcBounds)
|
||||||
} else {
|
} else {
|
||||||
dstBounds = srcBounds
|
dstBounds = srcBounds
|
||||||
@ -38,7 +24,7 @@ func (p *autoRotateFilter) Bounds(srcBounds image.Rectangle) (dstBounds image.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
func (p *autoRotateFilter) Draw(dst draw.Image, src image.Image, options *gift.Options) {
|
||||||
if p.needRotate(src.Bounds()) {
|
if src.Bounds().Dx() > src.Bounds().Dy() {
|
||||||
gift.Rotate90().Draw(dst, src, options)
|
gift.Rotate90().Draw(dst, src, options)
|
||||||
} else {
|
} else {
|
||||||
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
|
||||||
|
@ -10,7 +10,7 @@ func NewGift(options *Options) *gift.GIFT {
|
|||||||
g.SetParallelization(false)
|
g.SetParallelization(false)
|
||||||
|
|
||||||
if options.AutoRotate {
|
if options.AutoRotate {
|
||||||
g.Add(epubfilters.AutoRotate(options.ViewWidth, options.ViewHeight))
|
g.Add(epubfilters.AutoRotate())
|
||||||
}
|
}
|
||||||
if options.Contrast != 0 {
|
if options.Contrast != 0 {
|
||||||
g.Add(gift.Contrast(float32(options.Contrast)))
|
g.Add(gift.Contrast(float32(options.Contrast)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user