diff --git a/internal/converter/converter.go b/internal/converter/converter.go index ccc6075..3417b8f 100644 --- a/internal/converter/converter.go +++ b/internal/converter/converter.go @@ -107,7 +107,7 @@ func (c *Converter) InitParse() { c.AddBoolParam(&c.Options.AutoRotate, "autorotate", c.Options.AutoRotate, "Auto Rotate page when width > height") c.AddBoolParam(&c.Options.Auto, "auto", false, "Activate all automatic options") c.AddBoolParam(&c.Options.AutoSplitDoublePage, "autosplitdoublepage", c.Options.AutoSplitDoublePage, "Auto Split double page when width > height") - c.AddBoolParam(&c.Options.NoBlankPage, "noblankpage", c.Options.NoBlankPage, "Remove blank pages") + 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.") c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20") diff --git a/internal/converter/options/converter_options.go b/internal/converter/options/converter_options.go index 4750592..b2566d8 100644 --- a/internal/converter/options/converter_options.go +++ b/internal/converter/options/converter_options.go @@ -33,7 +33,7 @@ type Options struct { Auto bool `yaml:"-"` AutoRotate bool `yaml:"auto_rotate"` AutoSplitDoublePage bool `yaml:"auto_split_double_page"` - NoBlankPage bool `yaml:"no_blank_page"` + NoBlankImage bool `yaml:"no_blank_image"` Manga bool `yaml:"manga"` HasCover bool `yaml:"has_cover"` LimitMb int `yaml:"limit_mb"` @@ -71,7 +71,7 @@ func New() *Options { Contrast: 0, AutoRotate: false, AutoSplitDoublePage: false, - NoBlankPage: false, + NoBlankImage: true, Manga: false, HasCover: true, LimitMb: 0, @@ -172,7 +172,7 @@ func (o *Options) ShowConfig() string { Contrast : %d AutoRotate : %v AutoSplitDoublePage : %v - NoBlankPage : %v + NoBlankImage : %v Manga : %v HasCover : %v LimitMb : %s @@ -188,7 +188,7 @@ func (o *Options) ShowConfig() string { o.Contrast, o.AutoRotate, o.AutoSplitDoublePage, - o.NoBlankPage, + o.NoBlankImage, o.Manga, o.HasCover, limitmb, diff --git a/internal/epub/image/epub_image.go b/internal/epub/image/epub_image.go index 74b4b41..8a4acfb 100644 --- a/internal/epub/image/epub_image.go +++ b/internal/epub/image/epub_image.go @@ -15,6 +15,7 @@ type Image struct { Width int Height int IsCover bool + IsBlank bool DoublePage bool Path string Name string diff --git a/internal/epub/imageprocessor/epub_image_processor.go b/internal/epub/imageprocessor/epub_image_processor.go index f36773f..c83f3f1 100644 --- a/internal/epub/imageprocessor/epub_image_processor.go +++ b/internal/epub/imageprocessor/epub_image_processor.go @@ -96,6 +96,7 @@ func (e *EpubImageProcessor) Load() (LoadedImages, error) { Width: dst.Bounds().Dx(), Height: dst.Bounds().Dy(), IsCover: input.Id == 0 && part == 0, + IsBlank: dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1, DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(), Path: input.Path, Name: input.Name, @@ -118,7 +119,7 @@ func (e *EpubImageProcessor) Load() (LoadedImages, error) { if output.Image.Part == 0 { bar.Add(1) } - if e.Image.NoBlankPage && output.Image.Width == 1 && output.Image.Height == 1 { + if e.Image.NoBlankImage && output.Image.IsBlank { continue } images = append(images, output) @@ -138,7 +139,8 @@ func (e *EpubImageProcessor) transformImage(src image.Image, srcId int) []image. var filters, splitFilter []gift.Filter var images []image.Image - if e.Image.Crop.Enabled { + // Lookup for margin if crop is enable or if we want to remove blank image + if e.Image.Crop.Enabled || e.Image.NoBlankImage { f := epubimagefilters.AutoCrop( src, e.Image.Crop.Left, @@ -146,8 +148,16 @@ func (e *EpubImageProcessor) transformImage(src image.Image, srcId int) []image. e.Image.Crop.Right, e.Image.Crop.Bottom, ) - filters = append(filters, f) - splitFilter = append(splitFilter, f) + + // detect if blank image + size := f.Bounds(src.Bounds()) + isBlank := size.Dx() == 0 && size.Dy() == 0 + + // crop is enable or if blank image with noblankimage options + if e.Image.Crop.Enabled || (e.Image.NoBlankImage && isBlank) { + filters = append(filters, f) + splitFilter = append(splitFilter, f) + } } if e.Image.AutoRotate && src.Bounds().Dx() > src.Bounds().Dy() { diff --git a/internal/epub/options/epub_options.go b/internal/epub/options/epub_options.go index d806297..2b9e5b6 100644 --- a/internal/epub/options/epub_options.go +++ b/internal/epub/options/epub_options.go @@ -19,7 +19,7 @@ type Image struct { Contrast int AutoRotate bool AutoSplitDoublePage bool - NoBlankPage bool + NoBlankImage bool Manga bool HasCover bool View *View diff --git a/main.go b/main.go index 94cde4f..f592af9 100644 --- a/main.go +++ b/main.go @@ -126,7 +126,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s Contrast: cmd.Options.Contrast, AutoRotate: cmd.Options.AutoRotate, AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage, - NoBlankPage: cmd.Options.NoBlankPage, + NoBlankImage: cmd.Options.NoBlankImage, Manga: cmd.Options.Manga, HasCover: cmd.Options.HasCover, View: &epuboptions.View{