mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
add option keepdoublepageifsplitted
This commit is contained in:
parent
7ea9b9f86e
commit
21cbde14bc
@ -119,6 +119,7 @@ func (c *Converter) InitParse() {
|
||||
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.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.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.")
|
||||
|
@ -35,6 +35,7 @@ type Options struct {
|
||||
AutoContrast bool `yaml:"auto_contrast"`
|
||||
AutoRotate bool `yaml:"auto_rotate"`
|
||||
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
|
||||
KeepDoublePageIfSplitted bool `yaml:"keep_double_page_if_splitted"`
|
||||
NoBlankImage bool `yaml:"no_blank_image"`
|
||||
Manga bool `yaml:"manga"`
|
||||
HasCover bool `yaml:"has_cover"`
|
||||
@ -77,22 +78,23 @@ type Options struct {
|
||||
// Initialize default options.
|
||||
func New() *Options {
|
||||
return &Options{
|
||||
Profile: "SR",
|
||||
Quality: 85,
|
||||
Grayscale: true,
|
||||
Crop: true,
|
||||
CropRatioLeft: 1,
|
||||
CropRatioUp: 1,
|
||||
CropRatioRight: 1,
|
||||
CropRatioBottom: 3,
|
||||
NoBlankImage: true,
|
||||
HasCover: true,
|
||||
SortPathMode: 1,
|
||||
ForegroundColor: "000",
|
||||
BackgroundColor: "FFF",
|
||||
Format: "jpeg",
|
||||
TitlePage: 1,
|
||||
profiles: profiles.New(),
|
||||
Profile: "SR",
|
||||
Quality: 85,
|
||||
Grayscale: true,
|
||||
Crop: true,
|
||||
CropRatioLeft: 1,
|
||||
CropRatioUp: 1,
|
||||
CropRatioRight: 1,
|
||||
CropRatioBottom: 3,
|
||||
NoBlankImage: true,
|
||||
HasCover: true,
|
||||
KeepDoublePageIfSplitted: true,
|
||||
SortPathMode: 1,
|
||||
ForegroundColor: "000",
|
||||
BackgroundColor: "FFF",
|
||||
Format: "jpeg",
|
||||
TitlePage: 1,
|
||||
profiles: profiles.New(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,6 +210,7 @@ func (o *Options) ShowConfig() string {
|
||||
{"AutoContrast", o.AutoContrast, true},
|
||||
{"AutoRotate", o.AutoRotate, true},
|
||||
{"AutoSplitDoublePage", o.AutoSplitDoublePage, true},
|
||||
{"KeepDoublePageIfSplitted", o.KeepDoublePageIfSplitted, o.AutoSplitDoublePage},
|
||||
{"NoBlankImage", o.NoBlankImage, true},
|
||||
{"Manga", o.Manga, true},
|
||||
{"HasCover", o.HasCover, true},
|
||||
|
@ -442,7 +442,10 @@ func (e *ePub) Write() error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
@ -101,6 +101,14 @@ func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err 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 {
|
||||
bar.Close()
|
||||
fmt.Fprintf(os.Stderr, "error with %s: %s", input.Name, err)
|
||||
|
@ -22,21 +22,22 @@ type View struct {
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
Crop *Crop
|
||||
Quality int
|
||||
Brightness int
|
||||
Contrast int
|
||||
AutoContrast bool
|
||||
AutoRotate bool
|
||||
AutoSplitDoublePage bool
|
||||
NoBlankImage bool
|
||||
Manga bool
|
||||
HasCover bool
|
||||
View *View
|
||||
GrayScale bool
|
||||
GrayScaleMode int
|
||||
Resize bool
|
||||
Format string
|
||||
Crop *Crop
|
||||
Quality int
|
||||
Brightness int
|
||||
Contrast int
|
||||
AutoContrast bool
|
||||
AutoRotate bool
|
||||
AutoSplitDoublePage bool
|
||||
KeepDoublePageIfSplitted bool
|
||||
NoBlankImage bool
|
||||
Manga bool
|
||||
HasCover bool
|
||||
View *View
|
||||
GrayScale bool
|
||||
GrayScaleMode int
|
||||
Resize bool
|
||||
Format string
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
|
@ -174,7 +174,12 @@ func getManifest(o *ContentOptions) []tag {
|
||||
|
||||
lastImage := o.Images[len(o.Images)-1]
|
||||
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...)
|
||||
@ -212,7 +217,7 @@ func getSpineAuto(o *ContentOptions) []tag {
|
||||
)
|
||||
}
|
||||
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{
|
||||
"itemref",
|
||||
tagAttrs{"idref": img.SpaceKey(), "properties": getSpreadBlank()},
|
||||
|
31
main.go
31
main.go
@ -114,21 +114,22 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
||||
DryVerbose: cmd.Options.DryVerbose,
|
||||
Quiet: cmd.Options.Quiet,
|
||||
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},
|
||||
Quality: cmd.Options.Quality,
|
||||
Brightness: cmd.Options.Brightness,
|
||||
Contrast: cmd.Options.Contrast,
|
||||
AutoContrast: cmd.Options.AutoContrast,
|
||||
AutoRotate: cmd.Options.AutoRotate,
|
||||
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
|
||||
NoBlankImage: cmd.Options.NoBlankImage,
|
||||
Manga: cmd.Options.Manga,
|
||||
HasCover: cmd.Options.HasCover,
|
||||
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}},
|
||||
GrayScale: cmd.Options.Grayscale,
|
||||
GrayScaleMode: cmd.Options.GrayscaleMode,
|
||||
Resize: !cmd.Options.NoResize,
|
||||
Format: cmd.Options.Format,
|
||||
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,
|
||||
Brightness: cmd.Options.Brightness,
|
||||
Contrast: cmd.Options.Contrast,
|
||||
AutoContrast: cmd.Options.AutoContrast,
|
||||
AutoRotate: cmd.Options.AutoRotate,
|
||||
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
|
||||
KeepDoublePageIfSplitted: cmd.Options.KeepDoublePageIfSplitted,
|
||||
NoBlankImage: cmd.Options.NoBlankImage,
|
||||
Manga: cmd.Options.Manga,
|
||||
HasCover: cmd.Options.HasCover,
|
||||
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}},
|
||||
GrayScale: cmd.Options.Grayscale,
|
||||
GrayScaleMode: cmd.Options.GrayscaleMode,
|
||||
Resize: !cmd.Options.NoResize,
|
||||
Format: cmd.Options.Format,
|
||||
},
|
||||
}).Write(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user