add gif support

This commit is contained in:
Milan Nikolic
2015-11-03 19:47:24 +01:00
parent ca4f13ebfe
commit 4abf99a644
2 changed files with 29 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ Features
- reads RAR, ZIP, 7Z, GZ, BZ2, CBR, CBZ, CB7, CBT, PDF, EPUB, XPS and plain directory - reads RAR, ZIP, 7Z, GZ, BZ2, CBR, CBZ, CB7, CBT, PDF, EPUB, XPS and plain directory
- always saves processed comic in CBZ (ZIP) archive format - always saves processed comic in CBZ (ZIP) archive format
- images can be converted to JPEG, PNG or 4-Bit BMP (16 colors) file format - images can be converted to JPEG, PNG, GIF or 4-Bit BMP (16 colors) file format
- reads JPEG, PNG, BMP, GIF, TIFF and WEBP file formats - reads JPEG, PNG, BMP, GIF, TIFF and WEBP file formats
- choose resize algorithm (NearestNeighbor, Bilinear, Bicubic, MitchellNetravali, Lanczos2/3) - choose resize algorithm (NearestNeighbor, Bilinear, Bicubic, MitchellNetravali, Lanczos2/3)
- export covers from comics - export covers from comics
@@ -20,10 +20,10 @@ Features
Download Download
-------- --------
- [Windows static build](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0.zip) - [Windows binary](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0.zip)
- [Linux 64bit build](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0.tar.gz) - [Linux 64bit binary](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0.tar.gz)
- [Linux 64bit static build](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0-static.tar.gz) - [Linux 64bit static binary](https://github.com/gen2brain/cbconvert/releases/download/0.3.0/cbconvert-0.3.0-static.tar.gz)
Using Using
----- -----
@@ -37,6 +37,7 @@ Using
--version Show application version. --version Show application version.
-p, --png encode images to PNG instead of JPEG -p, --png encode images to PNG instead of JPEG
-b, --bmp encode images to 4-Bit BMP instead of JPEG -b, --bmp encode images to 4-Bit BMP instead of JPEG
-g, --gif encode images to GIF instead of JPEG
-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

View File

@@ -62,7 +62,8 @@ var (
// Command line options // Command line options
type options struct { type options struct {
ToPNG bool // encode images to PNG instead of JPEG ToPNG bool // encode images to PNG instead of JPEG
ToBMP bool // encode images to 4-Bit BMP 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
Quality int // JPEG image quality Quality int // JPEG image quality
NoRGB bool // do not convert images with RGB colorspace NoRGB bool // do not convert images with RGB colorspace
Width uint // image width Width uint // image width
@@ -92,6 +93,8 @@ func convertImage(img image.Image, index int, pathName string) {
ext = "png" ext = "png"
} else if opts.ToBMP { } else if opts.ToBMP {
ext = "bmp" ext = "bmp"
} else if opts.ToGIF {
ext = "gif"
} }
var filename string var filename string
@@ -118,7 +121,7 @@ func convertImage(img image.Image, index int, pathName string) {
defer f.Close() defer f.Close()
png.Encode(f, i) png.Encode(f, i)
} else if opts.ToBMP { } else if opts.ToBMP {
// convert image to 4-Bit - 16 colors BMP // convert image to 4-Bit BMP (16 colors)
imagick.Initialize() imagick.Initialize()
mw := imagick.NewMagickWand() mw := imagick.NewMagickWand()
@@ -143,6 +146,22 @@ func convertImage(img image.Image, index int, pathName string) {
mw.SetImageCompression(imagick.COMPRESSION_NO) mw.SetImageCompression(imagick.COMPRESSION_NO)
mw.QuantizeImage(16, imagick.COLORSPACE_SRGB, 8, true, true) mw.QuantizeImage(16, imagick.COLORSPACE_SRGB, 8, true, true)
mw.WriteImage(fmt.Sprintf("BMP3:%s", filename)) mw.WriteImage(fmt.Sprintf("BMP3:%s", filename))
} else if opts.ToGIF {
// convert image to GIF
imagick.Initialize()
mw := imagick.NewMagickWand()
defer mw.Destroy()
b := new(bytes.Buffer)
jpeg.Encode(b, i, &jpeg.Options{jpeg.DefaultQuality})
err := mw.ReadImageBlob(b.Bytes())
if err != nil {
fmt.Fprintf(os.Stderr, "Error ReadImageBlob: %v\n", err.Error())
}
mw.SetImageFormat("gif")
mw.WriteImage(filename)
} else { } else {
// convert image to JPEG (default) // convert image to JPEG (default)
f, err := os.Create(filename) f, err := os.Create(filename)
@@ -772,7 +791,8 @@ func parseFlags() {
kingpin.Version("CBconvert 0.3.0") kingpin.Version("CBconvert 0.3.0")
kingpin.CommandLine.Help = "Comic Book convert tool." kingpin.CommandLine.Help = "Comic Book convert tool."
kingpin.Flag("png", "encode images to PNG instead of JPEG").Short('p').BoolVar(&opts.ToPNG) kingpin.Flag("png", "encode images to PNG instead of JPEG").Short('p').BoolVar(&opts.ToPNG)
kingpin.Flag("bmp", "encode images to 4-Bit BMP instead of JPEG").Short('b').BoolVar(&opts.ToBMP) kingpin.Flag("bmp", "encode images to 4-Bit BMP (16 colors) instead of JPEG").Short('b').BoolVar(&opts.ToBMP)
kingpin.Flag("gif", "encode images to GIF instead of JPEG").Short('g').BoolVar(&opts.ToGIF)
kingpin.Flag("width", "image width").Default(strconv.Itoa(0)).Short('w').UintVar(&opts.Width) kingpin.Flag("width", "image width").Default(strconv.Itoa(0)).Short('w').UintVar(&opts.Width)
kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').UintVar(&opts.Height) kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').UintVar(&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)
@@ -797,6 +817,7 @@ func main() {
signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
go func() { go func() {
for _ = range c { for _ = range c {
fmt.Fprintf(os.Stderr, "Aborting\n")
os.RemoveAll(workdir) os.RemoveAll(workdir)
os.Exit(1) os.Exit(1)
} }