mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
add manga mode
This commit is contained in:
parent
eef33a4c40
commit
5f661aec57
@ -92,6 +92,8 @@ Usage of go-comic-converter:
|
|||||||
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
|
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
|
||||||
-limitmb int
|
-limitmb int
|
||||||
Limit size of the ePub: Default nolimit (0), Minimum 20
|
Limit size of the ePub: Default nolimit (0), Minimum 20
|
||||||
|
-manga
|
||||||
|
Manga mode (right to left)
|
||||||
-nocrop
|
-nocrop
|
||||||
Disable cropping
|
Disable cropping
|
||||||
-output string
|
-output string
|
||||||
|
@ -22,6 +22,7 @@ type ImageOptions struct {
|
|||||||
Contrast int
|
Contrast int
|
||||||
AutoRotate bool
|
AutoRotate bool
|
||||||
AutoSplitDoublePage bool
|
AutoSplitDoublePage bool
|
||||||
|
Manga bool
|
||||||
Workers int
|
Workers int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +187,10 @@ func (e *ePub) Write() error {
|
|||||||
|
|
||||||
for _, img := range part.Images {
|
for _, img := range part.Images {
|
||||||
text := fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part)
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := wz.WriteImage(img.Data); err != nil {
|
if err := wz.WriteImage(img.Data); err != nil {
|
||||||
|
@ -28,12 +28,14 @@ func NewGift(options *ImageOptions) *gift.GIFT {
|
|||||||
func NewGiftSplitDoublePage(options *ImageOptions) []*gift.GIFT {
|
func NewGiftSplitDoublePage(options *ImageOptions) []*gift.GIFT {
|
||||||
gifts := make([]*gift.GIFT, 2)
|
gifts := make([]*gift.GIFT, 2)
|
||||||
|
|
||||||
|
rightFirst := options.Manga
|
||||||
|
|
||||||
gifts[0] = gift.New(
|
gifts[0] = gift.New(
|
||||||
filters.CropSplitDoublePage(false),
|
filters.CropSplitDoublePage(rightFirst),
|
||||||
)
|
)
|
||||||
|
|
||||||
gifts[1] = gift.New(
|
gifts[1] = gift.New(
|
||||||
filters.CropSplitDoublePage(true),
|
filters.CropSplitDoublePage(!rightFirst),
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, g := range gifts {
|
for _, g := range gifts {
|
||||||
|
@ -30,10 +30,19 @@
|
|||||||
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</manifest>
|
</manifest>
|
||||||
<spine page-progression-direction="ltr" toc="ncx">
|
{{ if .Info.Manga }}
|
||||||
|
<spine page-progression-direction="rtl" toc="ncx">
|
||||||
<itemref idref="page_part" linear="yes" properties="page-spread-right"/>
|
<itemref idref="page_part" linear="yes" properties="page-spread-right"/>
|
||||||
{{ range $idx, $ := .Images }}
|
{{ range $idx, $ := .Images }}
|
||||||
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}left{{ else }}right{{ end }}"/>
|
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}left{{ else }}right{{ end }}"/>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</spine>
|
</spine>
|
||||||
|
{{ else }}
|
||||||
|
<spine page-progression-direction="ltr" toc="ncx">
|
||||||
|
<itemref idref="page_part" linear="yes" properties="page-spread-left"/>
|
||||||
|
{{ range $idx, $ := .Images }}
|
||||||
|
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}right{{ else }}end{{ end }}"/>
|
||||||
|
{{ end }}
|
||||||
|
</spine>
|
||||||
|
{{ end }}
|
||||||
</package>
|
</package>
|
||||||
|
@ -2,39 +2,39 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||||
<head>
|
<head>
|
||||||
<title>Page {{ .Id }}_p{{ .Part}}</title>
|
<title>Page {{ .Image.Id }}_p{{ .Image.Part}}</title>
|
||||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||||
<meta name="viewport" content="width={{ .Width }}, height={{ .Height }}"/>
|
<meta name="viewport" content="width={{ .Image.Width }}, height={{ .Image.Height }}"/>
|
||||||
</head>
|
</head>
|
||||||
<body style="">
|
<body style="">
|
||||||
<div style="text-align:center;top:0.0%;">
|
<div style="text-align:center;top:0.0%;">
|
||||||
<img width="{{ .Width }}" height="{{ .Height }}" src="../Images/{{ .Id }}_p{{ .Part}}.jpg"/>
|
<img width="{{ .Image.Width }}" height="{{ .Image.Height }}" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg"/>
|
||||||
</div>
|
</div>
|
||||||
<div id="PV">
|
<div id="PV">
|
||||||
<div id="PV-TL">
|
<div id="PV-TL">
|
||||||
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TL-P", "ordinal":1}'></a>
|
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TL-P", "ordinal":{{ if .Manga }}2{{ else }}1{{ end }}}'></a>
|
||||||
</div>
|
</div>
|
||||||
<div id="PV-TR">
|
<div id="PV-TR">
|
||||||
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TR-P", "ordinal":2}'></a>
|
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-TR-P", "ordinal":{{ if .Manga }}1{{ else }}2{{ end }}}'></a>
|
||||||
</div>
|
</div>
|
||||||
<div id="PV-BL">
|
<div id="PV-BL">
|
||||||
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BL-P", "ordinal":3}'></a>
|
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BL-P", "ordinal":{{ if .Manga }}4{{ else }}3{{ end }}}'></a>
|
||||||
</div>
|
</div>
|
||||||
<div id="PV-BR">
|
<div id="PV-BR">
|
||||||
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BR-P", "ordinal":4}'></a>
|
<a style="display:inline-block;width:100%;height:100%;" class="app-amzn-magnify" data-app-amzn-magnify='{"targetId":"PV-BR-P", "ordinal":{{ if .Manga }}3{{ else }}4{{ end }}}'></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="PV-P" id="PV-TL-P" style="">
|
<div class="PV-P" id="PV-TL-P" style="">
|
||||||
<img style="position:absolute;left:0;top:0;" src="../Images/{{ .Id }}_p{{ .Part}}.jpg" width="{{ zoom .Width 1.5 }}" height="{{ zoom .Height 1.5 }}"/>
|
<img style="position:absolute;left:0;top:0;" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="PV-P" id="PV-TR-P" style="">
|
<div class="PV-P" id="PV-TR-P" style="">
|
||||||
<img style="position:absolute;right:0;top:0;" src="../Images/{{ .Id }}_p{{ .Part}}.jpg" width="{{ zoom .Width 1.5 }}" height="{{ zoom .Height 1.5 }}"/>
|
<img style="position:absolute;right:0;top:0;" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="PV-P" id="PV-BL-P" style="">
|
<div class="PV-P" id="PV-BL-P" style="">
|
||||||
<img style="position:absolute;left:0;bottom:0;" src="../Images/{{ .Id }}_p{{ .Part}}.jpg" width="{{ zoom .Width 1.5 }}" height="{{ zoom .Height 1.5 }}"/>
|
<img style="position:absolute;left:0;bottom:0;" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="PV-P" id="PV-BR-P" style="">
|
<div class="PV-P" id="PV-BR-P" style="">
|
||||||
<img style="position:absolute;right:0;bottom:0;" src="../Images/{{ .Id }}_p{{ .Part}}.jpg" width="{{ zoom .Width 1.5 }}" height="{{ zoom .Height 1.5 }}"/>
|
<img style="position:absolute;right:0;bottom:0;" src="../Images/{{ .Image.Id }}_p{{ .Image.Part}}.jpg" width="{{ zoom .Image.Width 1.5 }}" height="{{ zoom .Image.Height 1.5 }}"/>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
5
main.go
5
main.go
@ -69,6 +69,7 @@ type Option struct {
|
|||||||
Auto bool
|
Auto bool
|
||||||
AutoRotate bool
|
AutoRotate bool
|
||||||
AutoSplitDoublePage bool
|
AutoSplitDoublePage bool
|
||||||
|
Manga bool
|
||||||
Workers int
|
Workers int
|
||||||
LimitMb int
|
LimitMb int
|
||||||
}
|
}
|
||||||
@ -102,6 +103,7 @@ Options:
|
|||||||
Contrast : %d
|
Contrast : %d
|
||||||
AutoRotate : %v
|
AutoRotate : %v
|
||||||
AutoSplitDoublePage: %v
|
AutoSplitDoublePage: %v
|
||||||
|
Manga : %v
|
||||||
LimitMb : %s
|
LimitMb : %s
|
||||||
Workers : %d
|
Workers : %d
|
||||||
`,
|
`,
|
||||||
@ -116,6 +118,7 @@ Options:
|
|||||||
o.Contrast,
|
o.Contrast,
|
||||||
o.AutoRotate,
|
o.AutoRotate,
|
||||||
o.AutoSplitDoublePage,
|
o.AutoSplitDoublePage,
|
||||||
|
o.Manga,
|
||||||
limitmb,
|
limitmb,
|
||||||
o.Workers,
|
o.Workers,
|
||||||
)
|
)
|
||||||
@ -146,6 +149,7 @@ func main() {
|
|||||||
flag.BoolVar(&opt.Auto, "auto", false, "Activate all automatic options")
|
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.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.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.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
||||||
flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers")
|
flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers")
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
@ -251,6 +255,7 @@ func main() {
|
|||||||
Contrast: opt.Contrast,
|
Contrast: opt.Contrast,
|
||||||
AutoRotate: opt.AutoRotate,
|
AutoRotate: opt.AutoRotate,
|
||||||
AutoSplitDoublePage: opt.AutoSplitDoublePage,
|
AutoSplitDoublePage: opt.AutoSplitDoublePage,
|
||||||
|
Manga: opt.Manga,
|
||||||
Workers: opt.Workers,
|
Workers: opt.Workers,
|
||||||
},
|
},
|
||||||
}).Write(); err != nil {
|
}).Write(); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user