From c6fec88582893185018b55fb7eda17f5655a49fd Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Tue, 27 Dec 2022 14:52:05 +0100 Subject: [PATCH] add nocrop options --- internal/epub/core.go | 8 +++++++- main.go | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/epub/core.go b/internal/epub/core.go index 5a84165..d666284 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -43,6 +43,7 @@ type EPub struct { ViewWidth int ViewHeight int Quality int + Crop bool Images []*Images FirstImageTitle string @@ -92,6 +93,11 @@ func (e *EPub) SetQuality(q int) *EPub { return e } +func (e *EPub) SetCrop(c bool) *EPub { + e.Crop = c + return e +} + func (e *EPub) WriteFile(wz *zip.Writer, file, content string) error { m, err := wz.CreateHeader(&zip.FileHeader{ Name: file, @@ -171,7 +177,7 @@ func (e *EPub) LoadDir(dirname string) *EPub { go func() { defer wg.Done() for task := range todo { - data, w, h := imageconverter.Convert(task.Path, true, e.ViewWidth, e.ViewHeight, e.Quality) + data, w, h := imageconverter.Convert(task.Path, e.Crop, e.ViewWidth, e.ViewHeight, e.Quality) results <- &ImageDetails{task.Images, data, w, h} } }() diff --git a/main.go b/main.go index 5e3cf4f..b369aaa 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ type Option struct { Author string Title string Quality int + NoCrop bool } func (o *Option) String() string { @@ -43,6 +44,7 @@ func (o *Option) String() string { Author : %s Title : %s Quality: %d + Crop : %v `, o.Input, o.Output, @@ -53,6 +55,7 @@ func (o *Option) String() string { o.Author, o.Title, o.Quality, + !o.NoCrop, ) } @@ -69,6 +72,7 @@ func main() { flag.StringVar(&opt.Author, "author", "GO Comic Converter", "Author of the epub") flag.StringVar(&opt.Title, "title", "", "Title of the epub") flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image: Default 75") + flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping: Default false") flag.Parse() if opt.Input == "" || opt.Output == "" { @@ -92,6 +96,7 @@ func main() { err := epub.NewEpub(opt.Output). SetSize(profile.Width, profile.Height). SetQuality(opt.Quality). + SetCrop(!opt.NoCrop). SetTitle(opt.Title). SetAuthor(opt.Author). LoadDir(opt.Input).