mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
Compare commits
4 Commits
d1265a5135
...
f33c095094
Author | SHA1 | Date | |
---|---|---|---|
f33c095094 | |||
fee8a037dc | |||
7e3f0d4fcc | |||
0c09c85763 |
1
go.mod
1
go.mod
@ -23,6 +23,7 @@ require (
|
|||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
github.com/stretchr/testify v1.9.0 // indirect
|
||||||
|
github.com/viam-labs/go-libjpeg v0.3.1 // indirect
|
||||||
golang.org/x/net v0.25.0 // indirect
|
golang.org/x/net v0.25.0 // indirect
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
golang.org/x/term v0.20.0 // indirect
|
golang.org/x/term v0.20.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -39,6 +39,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
|||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
|
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
|
||||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
|
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
|
||||||
|
github.com/viam-labs/go-libjpeg v0.3.1 h1:J/byavXHFqRI1PFPrnPbP+wFCr1y+Cn1CwKXrORCPD0=
|
||||||
|
github.com/viam-labs/go-libjpeg v0.3.1/go.mod h1:b0ISpf9lJv9MO1h1gXAmSA/osG19cKGYjfYc6aeEjqs=
|
||||||
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
|
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
|
||||||
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
|
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
|
||||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Package options manage options with default value from config.
|
// Package converter options manage options with default value from config.
|
||||||
package converter
|
package converter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Package profiles manage supported profiles for go-comic-converter.
|
// Package converter profiles manage supported profiles for go-comic-converter.
|
||||||
package converter
|
package converter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -312,9 +312,10 @@ func (e EPUB) computeAspectRatio(epubParts []epubPart) float64 {
|
|||||||
return bestAspectRatio
|
return bestAspectRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EPUB) computeViewPort(epubParts []epubPart) {
|
func (e EPUB) computeViewPort(epubParts []epubPart) (int, int) {
|
||||||
if e.Image.View.AspectRatio == -1 {
|
if e.Image.View.AspectRatio == -1 {
|
||||||
return //keep device size
|
//keep device size
|
||||||
|
return e.Image.View.Width, e.Image.View.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
// readjusting view port
|
// readjusting view port
|
||||||
@ -325,9 +326,9 @@ func (e EPUB) computeViewPort(epubParts []epubPart) {
|
|||||||
|
|
||||||
viewWidth, viewHeight := int(float64(e.Image.View.Height)/bestAspectRatio), int(float64(e.Image.View.Width)*bestAspectRatio)
|
viewWidth, viewHeight := int(float64(e.Image.View.Height)/bestAspectRatio), int(float64(e.Image.View.Width)*bestAspectRatio)
|
||||||
if viewWidth > e.Image.View.Width {
|
if viewWidth > e.Image.View.Width {
|
||||||
e.Image.View.Height = viewHeight
|
return e.Image.View.Width, viewHeight
|
||||||
} else {
|
} else {
|
||||||
e.Image.View.Width = viewWidth
|
return viewWidth, e.Image.View.Height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +446,7 @@ func (e EPUB) Write() error {
|
|||||||
Json: e.Json,
|
Json: e.Json,
|
||||||
})
|
})
|
||||||
|
|
||||||
e.computeViewPort(epubParts)
|
e.Image.View.Width, e.Image.View.Height = e.computeViewPort(epubParts)
|
||||||
for i, part := range epubParts {
|
for i, part := range epubParts {
|
||||||
ext := filepath.Ext(e.Output)
|
ext := filepath.Ext(e.Output)
|
||||||
suffix := ""
|
suffix := ""
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Package epuboptions EPUBOptions for EPUB creation.
|
// Package epuboptions for EPUB creation.
|
||||||
package epuboptions
|
package epuboptions
|
||||||
|
|
||||||
type EPUBOptions struct {
|
type EPUBOptions struct {
|
||||||
|
@ -227,7 +227,7 @@ func (o Content) getSpineAuto() []tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, img := range o.Images {
|
for i, img := range o.Images {
|
||||||
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {
|
if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {
|
||||||
spine = append(spine, tag{
|
spine = append(spine, tag{
|
||||||
"itemref",
|
"itemref",
|
||||||
@ -242,6 +242,8 @@ func (o Content) getSpineAuto() []tag {
|
|||||||
tagAttrs{"idref": img.PageKey(), "properties": img.Position},
|
tagAttrs{"idref": img.PageKey(), "properties": img.Position},
|
||||||
"",
|
"",
|
||||||
})
|
})
|
||||||
|
// save position, img is a value type
|
||||||
|
o.Images[i] = img
|
||||||
}
|
}
|
||||||
if o.ImageOptions.Manga == isOnTheRight {
|
if o.ImageOptions.Manga == isOnTheRight {
|
||||||
spine = append(spine, tag{
|
spine = append(spine, tag{
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
mozJpeg "github.com/viam-labs/go-libjpeg/jpeg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
@ -28,7 +30,15 @@ func CompressImage(filename string, format string, img image.Image, quality int)
|
|||||||
case "png":
|
case "png":
|
||||||
err = png.Encode(&data, img)
|
err = png.Encode(&data, img)
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
err = jpeg.Encode(&data, img, &jpeg.Options{Quality: quality})
|
err = mozJpeg.Encode(&data, img, &mozJpeg.EncoderOptions{
|
||||||
|
Quality: quality,
|
||||||
|
OptimizeCoding: true,
|
||||||
|
ProgressiveMode: true,
|
||||||
|
DCTMethod: mozJpeg.DCTFloat,
|
||||||
|
})
|
||||||
|
if err != nil && err.Error() == "unsupported image type" {
|
||||||
|
err = jpeg.Encode(&data, img, &jpeg.Options{Quality: quality})
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unknown format %q", format)
|
err = fmt.Errorf("unknown format %q", format)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user