mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
change noblankpage by noblankimage
detect blank image even if crop is disabled
This commit is contained in:
parent
fd796be892
commit
1bc85f4c2d
@ -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.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.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.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.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.")
|
||||||
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
||||||
|
@ -33,7 +33,7 @@ type Options struct {
|
|||||||
Auto bool `yaml:"-"`
|
Auto bool `yaml:"-"`
|
||||||
AutoRotate bool `yaml:"auto_rotate"`
|
AutoRotate bool `yaml:"auto_rotate"`
|
||||||
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
|
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
|
||||||
NoBlankPage bool `yaml:"no_blank_page"`
|
NoBlankImage bool `yaml:"no_blank_image"`
|
||||||
Manga bool `yaml:"manga"`
|
Manga bool `yaml:"manga"`
|
||||||
HasCover bool `yaml:"has_cover"`
|
HasCover bool `yaml:"has_cover"`
|
||||||
LimitMb int `yaml:"limit_mb"`
|
LimitMb int `yaml:"limit_mb"`
|
||||||
@ -71,7 +71,7 @@ func New() *Options {
|
|||||||
Contrast: 0,
|
Contrast: 0,
|
||||||
AutoRotate: false,
|
AutoRotate: false,
|
||||||
AutoSplitDoublePage: false,
|
AutoSplitDoublePage: false,
|
||||||
NoBlankPage: false,
|
NoBlankImage: true,
|
||||||
Manga: false,
|
Manga: false,
|
||||||
HasCover: true,
|
HasCover: true,
|
||||||
LimitMb: 0,
|
LimitMb: 0,
|
||||||
@ -172,7 +172,7 @@ func (o *Options) ShowConfig() string {
|
|||||||
Contrast : %d
|
Contrast : %d
|
||||||
AutoRotate : %v
|
AutoRotate : %v
|
||||||
AutoSplitDoublePage : %v
|
AutoSplitDoublePage : %v
|
||||||
NoBlankPage : %v
|
NoBlankImage : %v
|
||||||
Manga : %v
|
Manga : %v
|
||||||
HasCover : %v
|
HasCover : %v
|
||||||
LimitMb : %s
|
LimitMb : %s
|
||||||
@ -188,7 +188,7 @@ func (o *Options) ShowConfig() string {
|
|||||||
o.Contrast,
|
o.Contrast,
|
||||||
o.AutoRotate,
|
o.AutoRotate,
|
||||||
o.AutoSplitDoublePage,
|
o.AutoSplitDoublePage,
|
||||||
o.NoBlankPage,
|
o.NoBlankImage,
|
||||||
o.Manga,
|
o.Manga,
|
||||||
o.HasCover,
|
o.HasCover,
|
||||||
limitmb,
|
limitmb,
|
||||||
|
@ -15,6 +15,7 @@ type Image struct {
|
|||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
IsCover bool
|
IsCover bool
|
||||||
|
IsBlank bool
|
||||||
DoublePage bool
|
DoublePage bool
|
||||||
Path string
|
Path string
|
||||||
Name string
|
Name string
|
||||||
|
@ -96,6 +96,7 @@ func (e *EpubImageProcessor) Load() (LoadedImages, error) {
|
|||||||
Width: dst.Bounds().Dx(),
|
Width: dst.Bounds().Dx(),
|
||||||
Height: dst.Bounds().Dy(),
|
Height: dst.Bounds().Dy(),
|
||||||
IsCover: input.Id == 0 && part == 0,
|
IsCover: input.Id == 0 && part == 0,
|
||||||
|
IsBlank: dst.Bounds().Dx() == 1 && dst.Bounds().Dy() == 1,
|
||||||
DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(),
|
DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(),
|
||||||
Path: input.Path,
|
Path: input.Path,
|
||||||
Name: input.Name,
|
Name: input.Name,
|
||||||
@ -118,7 +119,7 @@ func (e *EpubImageProcessor) Load() (LoadedImages, error) {
|
|||||||
if output.Image.Part == 0 {
|
if output.Image.Part == 0 {
|
||||||
bar.Add(1)
|
bar.Add(1)
|
||||||
}
|
}
|
||||||
if e.Image.NoBlankPage && output.Image.Width == 1 && output.Image.Height == 1 {
|
if e.Image.NoBlankImage && output.Image.IsBlank {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
images = append(images, output)
|
images = append(images, output)
|
||||||
@ -138,7 +139,8 @@ func (e *EpubImageProcessor) transformImage(src image.Image, srcId int) []image.
|
|||||||
var filters, splitFilter []gift.Filter
|
var filters, splitFilter []gift.Filter
|
||||||
var images []image.Image
|
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(
|
f := epubimagefilters.AutoCrop(
|
||||||
src,
|
src,
|
||||||
e.Image.Crop.Left,
|
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.Right,
|
||||||
e.Image.Crop.Bottom,
|
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() {
|
if e.Image.AutoRotate && src.Bounds().Dx() > src.Bounds().Dy() {
|
||||||
|
@ -19,7 +19,7 @@ type Image struct {
|
|||||||
Contrast int
|
Contrast int
|
||||||
AutoRotate bool
|
AutoRotate bool
|
||||||
AutoSplitDoublePage bool
|
AutoSplitDoublePage bool
|
||||||
NoBlankPage bool
|
NoBlankImage bool
|
||||||
Manga bool
|
Manga bool
|
||||||
HasCover bool
|
HasCover bool
|
||||||
View *View
|
View *View
|
||||||
|
2
main.go
2
main.go
@ -126,7 +126,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
Contrast: cmd.Options.Contrast,
|
Contrast: cmd.Options.Contrast,
|
||||||
AutoRotate: cmd.Options.AutoRotate,
|
AutoRotate: cmd.Options.AutoRotate,
|
||||||
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
|
AutoSplitDoublePage: cmd.Options.AutoSplitDoublePage,
|
||||||
NoBlankPage: cmd.Options.NoBlankPage,
|
NoBlankImage: cmd.Options.NoBlankImage,
|
||||||
Manga: cmd.Options.Manga,
|
Manga: cmd.Options.Manga,
|
||||||
HasCover: cmd.Options.HasCover,
|
HasCover: cmd.Options.HasCover,
|
||||||
View: &epuboptions.View{
|
View: &epuboptions.View{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user