add nocrop options

This commit is contained in:
Celogeek 2022-12-27 14:52:05 +01:00
parent d9a8575898
commit c6fec88582
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 12 additions and 1 deletions

View File

@ -43,6 +43,7 @@ type EPub struct {
ViewWidth int ViewWidth int
ViewHeight int ViewHeight int
Quality int Quality int
Crop bool
Images []*Images Images []*Images
FirstImageTitle string FirstImageTitle string
@ -92,6 +93,11 @@ func (e *EPub) SetQuality(q int) *EPub {
return e 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 { func (e *EPub) WriteFile(wz *zip.Writer, file, content string) error {
m, err := wz.CreateHeader(&zip.FileHeader{ m, err := wz.CreateHeader(&zip.FileHeader{
Name: file, Name: file,
@ -171,7 +177,7 @@ func (e *EPub) LoadDir(dirname string) *EPub {
go func() { go func() {
defer wg.Done() defer wg.Done()
for task := range todo { 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} results <- &ImageDetails{task.Images, data, w, h}
} }
}() }()

View File

@ -25,6 +25,7 @@ type Option struct {
Author string Author string
Title string Title string
Quality int Quality int
NoCrop bool
} }
func (o *Option) String() string { func (o *Option) String() string {
@ -43,6 +44,7 @@ func (o *Option) String() string {
Author : %s Author : %s
Title : %s Title : %s
Quality: %d Quality: %d
Crop : %v
`, `,
o.Input, o.Input,
o.Output, o.Output,
@ -53,6 +55,7 @@ func (o *Option) String() string {
o.Author, o.Author,
o.Title, o.Title,
o.Quality, 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.Author, "author", "GO Comic Converter", "Author of the epub")
flag.StringVar(&opt.Title, "title", "", "Title 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.IntVar(&opt.Quality, "quality", 85, "Quality of the image: Default 75")
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping: Default false")
flag.Parse() flag.Parse()
if opt.Input == "" || opt.Output == "" { if opt.Input == "" || opt.Output == "" {
@ -92,6 +96,7 @@ func main() {
err := epub.NewEpub(opt.Output). err := epub.NewEpub(opt.Output).
SetSize(profile.Width, profile.Height). SetSize(profile.Width, profile.Height).
SetQuality(opt.Quality). SetQuality(opt.Quality).
SetCrop(!opt.NoCrop).
SetTitle(opt.Title). SetTitle(opt.Title).
SetAuthor(opt.Author). SetAuthor(opt.Author).
LoadDir(opt.Input). LoadDir(opt.Input).