diff --git a/README.md b/README.md index 8f8b88d..57a11bb 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ Usage of go-comic-converter: Source of comic to convert: directory, cbz, zip, cbr, rar, pdf -limitmb int Limit size of the ePub: Default nolimit (0), Minimum 20 + -manga + Manga mode (right to left) -nocrop Disable cropping -output string diff --git a/internal/epub/core.go b/internal/epub/core.go index 4eb742f..6948360 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -22,6 +22,7 @@ type ImageOptions struct { Contrast int AutoRotate bool AutoSplitDoublePage bool + Manga bool Workers int } @@ -186,7 +187,10 @@ func (e *ePub) Write() error { for _, img := range part.Images { text := fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part) - if err := wz.WriteFile(text, e.render(textTmpl, img)); err != nil { + if err := wz.WriteFile(text, e.render(textTmpl, map[string]any{ + "Image": img, + "Manga": e.Manga, + })); err != nil { return err } if err := wz.WriteImage(img.Data); err != nil { diff --git a/internal/epub/image_filters.go b/internal/epub/image_filters.go index 204c271..75c5127 100644 --- a/internal/epub/image_filters.go +++ b/internal/epub/image_filters.go @@ -28,12 +28,14 @@ func NewGift(options *ImageOptions) *gift.GIFT { func NewGiftSplitDoublePage(options *ImageOptions) []*gift.GIFT { gifts := make([]*gift.GIFT, 2) + rightFirst := options.Manga + gifts[0] = gift.New( - filters.CropSplitDoublePage(false), + filters.CropSplitDoublePage(rightFirst), ) gifts[1] = gift.New( - filters.CropSplitDoublePage(true), + filters.CropSplitDoublePage(!rightFirst), ) for _, g := range gifts { diff --git a/internal/epub/templates/content.opf.tmpl b/internal/epub/templates/content.opf.tmpl index a212c0b..d2615df 100644 --- a/internal/epub/templates/content.opf.tmpl +++ b/internal/epub/templates/content.opf.tmpl @@ -30,10 +30,19 @@ {{ end }} - +{{ if .Info.Manga }} + {{ range $idx, $ := .Images }} {{ end }} +{{ else }} + + +{{ range $idx, $ := .Images }} + +{{ end }} + +{{ end }} diff --git a/internal/epub/templates/text.xhtml.tmpl b/internal/epub/templates/text.xhtml.tmpl index 921eda8..06c4469 100644 --- a/internal/epub/templates/text.xhtml.tmpl +++ b/internal/epub/templates/text.xhtml.tmpl @@ -2,39 +2,39 @@ -Page {{ .Id }}_p{{ .Part}} +Page {{ .Image.Id }}_p{{ .Image.Part}} - +
- +
- +
- +
- +
- +
- +
- +
- +
- +
\ No newline at end of file diff --git a/main.go b/main.go index 730b5e5..8e74dbc 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ type Option struct { Auto bool AutoRotate bool AutoSplitDoublePage bool + Manga bool Workers int LimitMb int } @@ -102,6 +103,7 @@ Options: Contrast : %d AutoRotate : %v AutoSplitDoublePage: %v + Manga : %v LimitMb : %s Workers : %d `, @@ -116,6 +118,7 @@ Options: o.Contrast, o.AutoRotate, o.AutoSplitDoublePage, + o.Manga, limitmb, o.Workers, ) @@ -146,6 +149,7 @@ func main() { flag.BoolVar(&opt.Auto, "auto", false, "Activate all automatic options") flag.BoolVar(&opt.AutoRotate, "autorotate", false, "Auto Rotate page when width > height") flag.BoolVar(&opt.AutoSplitDoublePage, "autosplitdoublepage", false, "Auto Split double page when width > height") + flag.BoolVar(&opt.Manga, "manga", false, "Manga mode (right to left)") flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20") flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers") flag.Usage = func() { @@ -251,6 +255,7 @@ func main() { Contrast: opt.Contrast, AutoRotate: opt.AutoRotate, AutoSplitDoublePage: opt.AutoSplitDoublePage, + Manga: opt.Manga, Workers: opt.Workers, }, }).Write(); err != nil {