mirror of
https://github.com/gen2brain/cbconvert
synced 2025-10-14 02:28:51 +02:00
best fit option
This commit is contained in:
@@ -54,12 +54,13 @@ Using
|
||||
|
||||
--width=0 Image width
|
||||
--height=0 Image height
|
||||
--fit Best fit for required width and height
|
||||
--quality=75 JPEG image quality
|
||||
--filter=2 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
|
||||
--png Encode images to PNG instead of JPEG
|
||||
--bmp Encode images to 4-Bit BMP (16 colors) instead of JPEG
|
||||
--gif Encode images to GIF instead of JPEG
|
||||
--rgb Convert images that have RGB colorspace (use --no-rgb if you only want to process grayscale images)
|
||||
--rgb Convert images that have RGB colorspace (use --no-rgb if you only want to convert grayscale images)
|
||||
--nonimage Leave non image files in archive (use --no-nonimage to remove non image files from archive)
|
||||
--grayscale Convert images to grayscale (monochromatic)
|
||||
--rotate=0 Rotate images, valid values are 0, 90, 180, 270
|
||||
|
@@ -89,6 +89,7 @@ type options struct {
|
||||
Quality int // JPEG image quality
|
||||
Width int // image width
|
||||
Height int // image height
|
||||
Fit bool // Best fit for required width and height
|
||||
Filter int // 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
|
||||
RGB bool // convert images that have RGB colorspace
|
||||
NonImage bool // Leave non image files in archive
|
||||
@@ -160,8 +161,12 @@ func transformImage(img image.Image) image.Image {
|
||||
var i image.Image = img
|
||||
|
||||
if opts.Width > 0 || opts.Height > 0 {
|
||||
if opts.Fit {
|
||||
i = imaging.Fit(i, opts.Width, opts.Height, filters[opts.Filter])
|
||||
} else {
|
||||
i = imaging.Resize(i, opts.Width, opts.Height, filters[opts.Filter])
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Rotate > 0 {
|
||||
switch opts.Rotate {
|
||||
@@ -896,6 +901,7 @@ func parseFlags() {
|
||||
convert.Arg("args", "filename or directory").Required().ExistingFilesOrDirsVar(&arguments)
|
||||
convert.Flag("width", "Image width").Default(strconv.Itoa(0)).IntVar(&opts.Width)
|
||||
convert.Flag("height", "Image height").Default(strconv.Itoa(0)).IntVar(&opts.Height)
|
||||
convert.Flag("fit", "Best fit for required width and height").BoolVar(&opts.Fit)
|
||||
convert.Flag("quality", "JPEG image quality").Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality)
|
||||
convert.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Default(strconv.Itoa(Linear)).IntVar(&opts.Filter)
|
||||
convert.Flag("png", "Encode images to PNG instead of JPEG").BoolVar(&opts.ToPNG)
|
||||
|
Reference in New Issue
Block a user