add limit option

This commit is contained in:
Celogeek 2022-12-27 15:32:54 +01:00
parent 0ee44ed40b
commit 95eb3497e7
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 21 additions and 7 deletions

View File

@ -45,6 +45,7 @@ type EPub struct {
ViewHeight int
Quality int
Crop bool
LimitMb int
Images []*Images
FirstImageTitle string
@ -99,6 +100,11 @@ func (e *EPub) SetCrop(c bool) *EPub {
return e
}
func (e *EPub) SetLimitMb(l int) *EPub {
e.LimitMb = l
return e
}
func (e *EPub) WriteString(wz *zip.Writer, file string, content string) error {
return e.WriteBuffer(wz, file, strings.NewReader(content))
}

View File

@ -26,6 +26,7 @@ type Option struct {
Title string
Quality int
NoCrop bool
LimitMb int
}
func (o *Option) String() string {
@ -36,6 +37,10 @@ func (o *Option) String() string {
width = profile.Width
height = profile.Height
}
limitmb := "nolimit"
if o.LimitMb > 0 {
limitmb = fmt.Sprintf("%d Mb", o.LimitMb)
}
return fmt.Sprintf(`Options:
Input : %s
@ -45,6 +50,7 @@ func (o *Option) String() string {
Title : %s
Quality: %d
Crop : %v
LimitMb: %s
`,
o.Input,
o.Output,
@ -56,6 +62,7 @@ func (o *Option) String() string {
o.Title,
o.Quality,
!o.NoCrop,
limitmb,
)
}
@ -73,6 +80,7 @@ func main() {
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.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit")
flag.Parse()
if opt.Input == "" || opt.Output == "" {