option to keep skip resize filter

This commit is contained in:
Celogeek 2023-05-01 17:09:47 +02:00
parent 13103b0eba
commit ee00ed2615
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
5 changed files with 16 additions and 8 deletions

View File

@ -120,6 +120,7 @@ func (c *Converter) InitParse() {
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file") c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file")
c.AddStringParam(&c.Options.ForegroundColor, "foreground-color", c.Options.ForegroundColor, "Foreground color in hexa format RGB. Black=000, White=FFF") c.AddStringParam(&c.Options.ForegroundColor, "foreground-color", c.Options.ForegroundColor, "Foreground color in hexa format RGB. Black=000, White=FFF")
c.AddStringParam(&c.Options.BackgroundColor, "background-color", c.Options.BackgroundColor, "Background color in hexa format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777") c.AddStringParam(&c.Options.BackgroundColor, "background-color", c.Options.BackgroundColor, "Background color in hexa format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777")
c.AddBoolParam(&c.Options.NoResize, "noresize", c.Options.NoResize, "Do not reduce image size if exceed device size")
c.AddSection("Default config") c.AddSection("Default config")
c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters") c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters")

View File

@ -42,6 +42,7 @@ type Options struct {
SortPathMode int `yaml:"sort_path_mode"` SortPathMode int `yaml:"sort_path_mode"`
ForegroundColor string `yaml:"foreground_color"` ForegroundColor string `yaml:"foreground_color"`
BackgroundColor string `yaml:"background_color"` BackgroundColor string `yaml:"background_color"`
NoResize bool `yaml:"noresize"`
// Default Config // Default Config
Show bool `yaml:"-"` Show bool `yaml:"-"`
@ -83,6 +84,7 @@ func New() *Options {
SortPathMode: 1, SortPathMode: 1,
ForegroundColor: "000", ForegroundColor: "000",
BackgroundColor: "FFF", BackgroundColor: "FFF",
NoResize: false,
profiles: profiles.New(), profiles: profiles.New(),
} }
} }
@ -191,6 +193,7 @@ func (o *Options) ShowConfig() string {
{"SortPathMode", sortpathmode}, {"SortPathMode", sortpathmode},
{"Foreground Color", fmt.Sprintf("#%s", o.ForegroundColor)}, {"Foreground Color", fmt.Sprintf("#%s", o.ForegroundColor)},
{"Background Color", fmt.Sprintf("#%s", o.BackgroundColor)}, {"Background Color", fmt.Sprintf("#%s", o.BackgroundColor)},
{"Resize", !o.NoResize},
} { } {
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V)) b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V))
} }

View File

@ -201,10 +201,12 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
splitFilter = append(splitFilter, f) splitFilter = append(splitFilter, f)
} }
filters = append(filters, if e.Image.Resize {
gift.ResizeToFit(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling), f := gift.ResizeToFit(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling)
epubimagefilters.Pixel(), filters = append(filters, f)
) }
filters = append(filters, epubimagefilters.Pixel())
// convert // convert
{ {
@ -232,10 +234,10 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
// convert double page // convert double page
for _, b := range []bool{e.Image.Manga, !e.Image.Manga} { for _, b := range []bool{e.Image.Manga, !e.Image.Manga} {
g := gift.New(splitFilter...) g := gift.New(splitFilter...)
g.Add( g.Add(epubimagefilters.CropSplitDoublePage(b))
epubimagefilters.CropSplitDoublePage(b), if e.Image.Resize {
gift.ResizeToFit(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling), g.Add(gift.ResizeToFit(e.Image.View.Width, e.Image.View.Height, gift.LanczosResampling))
) }
dst := e.createImage(src, g.Bounds(src.Bounds())) dst := e.createImage(src, g.Bounds(src.Bounds()))
g.Draw(dst, src) g.Draw(dst, src)
images = append(images, dst) images = append(images, dst)

View File

@ -31,6 +31,7 @@ type Image struct {
HasCover bool HasCover bool
View *View View *View
GrayScale bool GrayScale bool
Resize bool
} }
type Options struct { type Options struct {

View File

@ -138,6 +138,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
Background: cmd.Options.BackgroundColor, Background: cmd.Options.BackgroundColor,
}, },
}, },
Resize: !cmd.Options.NoResize,
}, },
}).Write(); err != nil { }).Write(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err) fmt.Fprintf(os.Stderr, "Error: %v\n", err)