add option to remove non-image files from archive

This commit is contained in:
Milan Nikolic
2015-11-04 00:28:18 +01:00
parent 85818eec5f
commit 82e8a6cbac
2 changed files with 26 additions and 21 deletions

View File

@@ -41,8 +41,9 @@ Using
-w, --width=0 image width -w, --width=0 image width
-h, --height=0 image height -h, --height=0 image height
-q, --quality=75 JPEG image quality -q, --quality=75 JPEG image quality
-n, --norgb do not convert images with RGB colorspace -f, --filter=2 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
-f, --filter=0 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos -N, --no_rgb do not convert images that have RGB colorspace
-I, --no_nonimage remove non image files from archive
-s, --suffix=SUFFIX add suffix to file basename -s, --suffix=SUFFIX add suffix to file basename
-c, --cover extract cover -c, --cover extract cover
-t, --thumbnail extract cover thumbnail (freedesktop spec.) -t, --thumbnail extract cover thumbnail (freedesktop spec.)

View File

@@ -87,10 +87,11 @@ type options struct {
ToBMP bool // encode images to 4-Bit BMP (16 colors) instead of JPEG ToBMP bool // encode images to 4-Bit BMP (16 colors) instead of JPEG
ToGIF bool // encode images to GIF instead of JPEG ToGIF bool // encode images to GIF instead of JPEG
Quality int // JPEG image quality Quality int // JPEG image quality
NoRGB bool // do not convert images that have RGB colorspace
Width int // image width Width int // image width
Height int // image height Height int // image height
Filter int // 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos Filter int // 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
NoRGB bool // do not convert images that have RGB colorspace
NoNonImage bool // remove non image files from archive
Suffix string // add suffix to file basename Suffix string // add suffix to file basename
Cover bool // extract cover Cover bool // extract cover
Thumbnail bool // extract cover thumbnail (freedesktop spec.) Thumbnail bool // extract cover thumbnail (freedesktop spec.)
@@ -326,9 +327,11 @@ func convertArchive(file string) {
go convertImage(img, 0, pathname) go convertImage(img, 0, pathname)
} }
} else { } else {
if !opts.NoNonImage {
copyFile(bytes.NewReader(buf), filepath.Join(workdir, filepath.Base(pathname))) copyFile(bytes.NewReader(buf), filepath.Join(workdir, filepath.Base(pathname)))
} }
} }
}
wg.Wait() wg.Wait()
} }
@@ -846,8 +849,9 @@ func parseFlags() {
kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').IntVar(&opts.Height) kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').IntVar(&opts.Height)
kingpin.Flag("quality", "JPEG image quality").Short('q').Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality) kingpin.Flag("quality", "JPEG image quality").Short('q').Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality)
kingpin.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Short('f'). kingpin.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Short('f').
Default(strconv.Itoa(NearestNeighbor)).IntVar(&opts.Filter) Default(strconv.Itoa(Linear)).IntVar(&opts.Filter)
kingpin.Flag("norgb", "do not convert images that have RGB colorspace").Short('n').BoolVar(&opts.NoRGB) kingpin.Flag("no_rgb", "do not convert images that have RGB colorspace").Short('N').BoolVar(&opts.NoRGB)
kingpin.Flag("no_nonimage", "remove non image files from archive").Short('I').BoolVar(&opts.NoNonImage)
kingpin.Flag("suffix", "add suffix to file basename").Short('s').StringVar(&opts.Suffix) kingpin.Flag("suffix", "add suffix to file basename").Short('s').StringVar(&opts.Suffix)
kingpin.Flag("cover", "extract cover").Short('c').BoolVar(&opts.Cover) kingpin.Flag("cover", "extract cover").Short('c').BoolVar(&opts.Cover)
kingpin.Flag("thumbnail", "extract cover thumbnail (freedesktop spec.)").Short('t').BoolVar(&opts.Thumbnail) kingpin.Flag("thumbnail", "extract cover thumbnail (freedesktop spec.)").Short('t').BoolVar(&opts.Thumbnail)