mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02: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
|
||||
-limitmb int
|
||||
Limit size of the ePub: Default nolimit (0), Minimum 20
|
||||
-manga
|
||||
Manga mode (right to left)
|
||||
-nocrop
|
||||
Disable cropping
|
||||
-output string
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -30,10 +30,19 @@
|
||||
<item id="img_{{ .Id }}_p{{ .Part}}" href="Images/{{ .Id }}_p{{ .Part}}.jpg" media-type="image/jpeg"/>
|
||||
{{ end }}
|
||||
</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"/>
|
||||
{{ range $idx, $ := .Images }}
|
||||
<itemref idref="page_{{ $.Id }}_p{{ $.Part }}" linear="yes" properties="page-spread-{{ if mod $idx 2 }}left{{ else }}right{{ end }}"/>
|
||||
{{ end }}
|
||||
</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>
|
||||
|
@ -2,39 +2,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||
<head>
|
||||
<title>Page {{ .Id }}_p{{ .Part}}</title>
|
||||
<title>Page {{ .Image.Id }}_p{{ .Image.Part}}</title>
|
||||
<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>
|
||||
<body style="">
|
||||
<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 id="PV">
|
||||
<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 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 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 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 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 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 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 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>
|
||||
</body>
|
||||
</html>
|
5
main.go
5
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user