mirror of
https://github.com/gen2brain/cbconvert
synced 2025-10-14 02:28:51 +02:00
add brightness and contrast options
This commit is contained in:
@@ -66,6 +66,8 @@ Using
|
||||
--grayscale Convert images to grayscale (monochromatic)
|
||||
--rotate=0 Rotate images, valid values are 0, 90, 180, 270
|
||||
--flip="none" Flip images, valid values are none, horizontal, vertical
|
||||
--brightness=0 Changes the brightness of the images, must be in range (-100, 100)
|
||||
--contrast=0 Changes the contrast of the images, must be in range (-100, 100)
|
||||
--suffix=SUFFIX Add suffix to file basename
|
||||
|
||||
cover [<flags>] <args>...
|
||||
|
12
cbconvert.go
12
cbconvert.go
@@ -101,6 +101,8 @@ type options struct {
|
||||
Grayscale bool // convert images to grayscale (monochromatic)
|
||||
Rotate int // Rotate images, valid values are 0, 90, 180, 270
|
||||
Flip string // Flip images, valid values are none, horizontal, vertical
|
||||
Brightness float64 // Changes the brightness of the images, must be in range (-100, 100)
|
||||
Contrast float64 // Changes the contrast of the images, must be in range (-100, 100)
|
||||
Recursive bool // process subdirectories recursively
|
||||
Size int64 // process only files larger then size (in MB)
|
||||
Quiet bool // hide console output
|
||||
@@ -194,6 +196,14 @@ func transformImage(img image.Image) image.Image {
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Brightness != 0 {
|
||||
i = imaging.AdjustBrightness(i, opts.Brightness)
|
||||
}
|
||||
|
||||
if opts.Contrast != 0 {
|
||||
i = imaging.AdjustContrast(i, opts.Contrast)
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -919,6 +929,8 @@ func parseFlags() {
|
||||
convert.Flag("grayscale", "Convert images to grayscale (monochromatic)").BoolVar(&opts.Grayscale)
|
||||
convert.Flag("rotate", "Rotate images, valid values are 0, 90, 180, 270").Default(strconv.Itoa(0)).IntVar(&opts.Rotate)
|
||||
convert.Flag("flip", "Flip images, valid values are none, horizontal, vertical").Default("none").StringVar(&opts.Flip)
|
||||
convert.Flag("brightness", "Changes the brightness of the images, must be in range (-100, 100)").Default(strconv.Itoa(0)).Float64Var(&opts.Brightness)
|
||||
convert.Flag("contrast", "Changes the contrast of the images, must be in range (-100, 100)").Default(strconv.Itoa(0)).Float64Var(&opts.Contrast)
|
||||
convert.Flag("suffix", "Add suffix to file basename").StringVar(&opts.Suffix)
|
||||
|
||||
cover := kingpin.Command("cover", "Extract cover")
|
||||
|
Reference in New Issue
Block a user