add option keepdoublepageifsplitted

This commit is contained in:
Celogeek 2023-09-23 09:51:47 +02:00
parent 7ea9b9f86e
commit 21cbde14bc
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
7 changed files with 71 additions and 49 deletions

View File

@ -119,6 +119,7 @@ func (c *Converter) InitParse() {
c.AddBoolParam(&c.Options.AutoContrast, "autocontrast", c.Options.AutoContrast, "Improve contrast automatically") c.AddBoolParam(&c.Options.AutoContrast, "autocontrast", c.Options.AutoContrast, "Improve contrast automatically")
c.AddBoolParam(&c.Options.AutoRotate, "autorotate", c.Options.AutoRotate, "Auto Rotate page when width > height") c.AddBoolParam(&c.Options.AutoRotate, "autorotate", c.Options.AutoRotate, "Auto Rotate page when width > height")
c.AddBoolParam(&c.Options.AutoSplitDoublePage, "autosplitdoublepage", c.Options.AutoSplitDoublePage, "Auto Split double page when width > height") c.AddBoolParam(&c.Options.AutoSplitDoublePage, "autosplitdoublepage", c.Options.AutoSplitDoublePage, "Auto Split double page when width > height")
c.AddBoolParam(&c.Options.KeepDoublePageIfSplitted, "keepdoublepageifsplitted", c.Options.KeepDoublePageIfSplitted, "Keep the double page if splitted")
c.AddBoolParam(&c.Options.NoBlankImage, "noblankimage", c.Options.NoBlankImage, "Remove blank image") c.AddBoolParam(&c.Options.NoBlankImage, "noblankimage", c.Options.NoBlankImage, "Remove blank image")
c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)") c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)")
c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.") c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.")

View File

@ -35,6 +35,7 @@ type Options struct {
AutoContrast bool `yaml:"auto_contrast"` AutoContrast bool `yaml:"auto_contrast"`
AutoRotate bool `yaml:"auto_rotate"` AutoRotate bool `yaml:"auto_rotate"`
AutoSplitDoublePage bool `yaml:"auto_split_double_page"` AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
KeepDoublePageIfSplitted bool `yaml:"keep_double_page_if_splitted"`
NoBlankImage bool `yaml:"no_blank_image"` NoBlankImage bool `yaml:"no_blank_image"`
Manga bool `yaml:"manga"` Manga bool `yaml:"manga"`
HasCover bool `yaml:"has_cover"` HasCover bool `yaml:"has_cover"`
@ -77,22 +78,23 @@ type Options struct {
// Initialize default options. // Initialize default options.
func New() *Options { func New() *Options {
return &Options{ return &Options{
Profile: "SR", Profile: "SR",
Quality: 85, Quality: 85,
Grayscale: true, Grayscale: true,
Crop: true, Crop: true,
CropRatioLeft: 1, CropRatioLeft: 1,
CropRatioUp: 1, CropRatioUp: 1,
CropRatioRight: 1, CropRatioRight: 1,
CropRatioBottom: 3, CropRatioBottom: 3,
NoBlankImage: true, NoBlankImage: true,
HasCover: true, HasCover: true,
SortPathMode: 1, KeepDoublePageIfSplitted: true,
ForegroundColor: "000", SortPathMode: 1,
BackgroundColor: "FFF", ForegroundColor: "000",
Format: "jpeg", BackgroundColor: "FFF",
TitlePage: 1, Format: "jpeg",
profiles: profiles.New(), TitlePage: 1,
profiles: profiles.New(),
} }
} }
@ -208,6 +210,7 @@ func (o *Options) ShowConfig() string {
{"AutoContrast", o.AutoContrast, true}, {"AutoContrast", o.AutoContrast, true},
{"AutoRotate", o.AutoRotate, true}, {"AutoRotate", o.AutoRotate, true},
{"AutoSplitDoublePage", o.AutoSplitDoublePage, true}, {"AutoSplitDoublePage", o.AutoSplitDoublePage, true},
{"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, o.AutoSplitDoublePage},
{"NoBlankImage", o.NoBlankImage, true}, {"NoBlankImage", o.NoBlankImage, true},
{"Manga", o.Manga, true}, {"Manga", o.Manga, true},
{"HasCover", o.HasCover, true}, {"HasCover", o.HasCover, true},

View File

@ -442,7 +442,10 @@ func (e *ePub) Write() error {
} }
// Double Page or Last Image that is not a double page // Double Page or Last Image that is not a double page
if !e.Image.View.PortraitOnly && (img.DoublePage || (img.Part == 0 && img == lastImage)) { if !e.Image.View.PortraitOnly &&
(img.DoublePage ||
(!e.Image.KeepDoublePageIfSplitted && img.Part == 1) ||
(img.Part == 0 && img == lastImage)) {
if err := e.writeBlank(wz, img); err != nil { if err := e.writeBlank(wz, img); err != nil {
return err return err
} }

View File

@ -101,6 +101,14 @@ func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) {
Error: input.Error, Error: input.Error,
} }
// do not keep double page if requested
if !img.IsCover &&
img.DoublePage &&
e.Options.Image.AutoSplitDoublePage &&
!e.Options.Image.KeepDoublePageIfSplitted {
continue
}
if err = imgStorage.Add(img.EPUBImgPath(), dst, e.Image.Quality); err != nil { if err = imgStorage.Add(img.EPUBImgPath(), dst, e.Image.Quality); err != nil {
bar.Close() bar.Close()
fmt.Fprintf(os.Stderr, "error with %s: %s", input.Name, err) fmt.Fprintf(os.Stderr, "error with %s: %s", input.Name, err)

View File

@ -22,21 +22,22 @@ type View struct {
} }
type Image struct { type Image struct {
Crop *Crop Crop *Crop
Quality int Quality int
Brightness int Brightness int
Contrast int Contrast int
AutoContrast bool AutoContrast bool
AutoRotate bool AutoRotate bool
AutoSplitDoublePage bool AutoSplitDoublePage bool
NoBlankImage bool KeepDoublePageIfSplitted bool
Manga bool NoBlankImage bool
HasCover bool Manga bool
View *View HasCover bool
GrayScale bool View *View
GrayScaleMode int GrayScale bool
Resize bool GrayScaleMode int
Format string Resize bool
Format string
} }
type Options struct { type Options struct {

View File

@ -174,7 +174,12 @@ func getManifest(o *ContentOptions) []tag {
lastImage := o.Images[len(o.Images)-1] lastImage := o.Images[len(o.Images)-1]
for _, img := range o.Images { for _, img := range o.Images {
addTag(img, !o.ImageOptions.View.PortraitOnly && (img.DoublePage || (img.Part == 0 && img == lastImage))) addTag(
img,
!o.ImageOptions.View.PortraitOnly &&
(img.DoublePage ||
(!o.ImageOptions.KeepDoublePageIfSplitted && img.Part == 1) ||
(img.Part == 0 && img == lastImage)))
} }
items = append(items, imageTags...) items = append(items, imageTags...)
@ -212,7 +217,7 @@ func getSpineAuto(o *ContentOptions) []tag {
) )
} }
for _, img := range o.Images { for _, img := range o.Images {
if img.DoublePage && o.ImageOptions.Manga == isOnTheRight { if (img.DoublePage || img.Part == 1) && o.ImageOptions.Manga == isOnTheRight {
spine = append(spine, tag{ spine = append(spine, tag{
"itemref", "itemref",
tagAttrs{"idref": img.SpaceKey(), "properties": getSpreadBlank()}, tagAttrs{"idref": img.SpaceKey(), "properties": getSpreadBlank()},

31
main.go
View File

@ -114,21 +114,22 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
DryVerbose: cmd.Options.DryVerbose, DryVerbose: cmd.Options.DryVerbose,
Quiet: cmd.Options.Quiet, Quiet: cmd.Options.Quiet,
Image: &epuboptions.Image{ Image: &epuboptions.Image{
Crop: &epuboptions.Crop{Enabled: cmd.Options.Crop, Left: cmd.Options.CropRatioLeft, Up: cmd.Options.CropRatioUp, Right: cmd.Options.CropRatioRight, Bottom: cmd.Options.CropRatioBottom}, Crop: &epuboptions.Crop{Enabled: cmd.Options.Crop, Left: cmd.Options.CropRatioLeft, Up: cmd.Options.CropRatioUp, Right: cmd.Options.CropRatioRight, Bottom: cmd.Options.CropRatioBottom},
Quality: cmd.Options.Quality, Quality: cmd.Options.Quality,
Brightness: cmd.Options.Brightness, Brightness: cmd.Options.Brightness,
Contrast: cmd.Options.Contrast, Contrast: cmd.Options.Contrast,
AutoContrast: cmd.Options.AutoContrast, AutoContrast: cmd.Options.AutoContrast,
AutoRotate: cmd.Options.AutoRotate, AutoRotate: cmd.Options.AutoRotate,
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage, AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
NoBlankImage: cmd.Options.NoBlankImage, KeepDoublePageIfSplitted: cmd.Options.KeepDoublePageIfSplitted,
Manga: cmd.Options.Manga, NoBlankImage: cmd.Options.NoBlankImage,
HasCover: cmd.Options.HasCover, Manga: cmd.Options.Manga,
View: &epuboptions.View{Width: profile.Width, Height: profile.Height, AspectRatio: cmd.Options.AspectRatio, PortraitOnly: cmd.Options.PortraitOnly, Color: epuboptions.Color{Foreground: cmd.Options.ForegroundColor, Background: cmd.Options.BackgroundColor}}, HasCover: cmd.Options.HasCover,
GrayScale: cmd.Options.Grayscale, View: &epuboptions.View{Width: profile.Width, Height: profile.Height, AspectRatio: cmd.Options.AspectRatio, PortraitOnly: cmd.Options.PortraitOnly, Color: epuboptions.Color{Foreground: cmd.Options.ForegroundColor, Background: cmd.Options.BackgroundColor}},
GrayScaleMode: cmd.Options.GrayscaleMode, GrayScale: cmd.Options.Grayscale,
Resize: !cmd.Options.NoResize, GrayScaleMode: cmd.Options.GrayscaleMode,
Format: cmd.Options.Format, Resize: !cmd.Options.NoResize,
Format: cmd.Options.Format,
}, },
}).Write(); err != nil { }).Write(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err) fmt.Fprintf(os.Stderr, "Error: %v\n", err)