add compiletime build tag 'disableimagecrush' to remove cgo dependency

This commit is contained in:
mappu 2018-06-04 17:41:07 +12:00
parent f0fe3685c2
commit 5603cdd393
3 changed files with 19 additions and 3 deletions

View File

@ -4,8 +4,6 @@ import (
"bytes"
"image"
"image/jpeg"
"code.ivysaur.me/imagequant"
)
func (this *Thumbnailer) RenderScaledImage(src image.Image) ([]byte, error) {
@ -60,7 +58,7 @@ func (this *Thumbnailer) RenderScaledImage(src image.Image) ([]byte, error) {
switch this.ofmt {
case OUTPUT_PNG_CRUSH:
return crush(dest, imagequant.SPEED_FASTEST)
return crushFast(dest)
case OUTPUT_JPG:
buff := bytes.Buffer{}

View File

@ -1,3 +1,5 @@
//+build !disableimagecrush
package thumbnail
import (
@ -51,6 +53,10 @@ func rgb8PaletteToGoImage(w, h int, rgb8data []byte, pal color.Palette) image.Im
return ret
}
func crushFast(img image.Image) ([]byte, error) {
return crush(img, imagequant.SPEED_FASTEST)
}
func crush(img image.Image, speed int) ([]byte, error) {
width := img.Bounds().Max.X

12
imagecrush_disabled.go Normal file
View File

@ -0,0 +1,12 @@
// +build disableimagecrush
package thumbnail
import (
"errors"
"image"
)
func crushFast(img image.Image) ([]byte, error) {
return nil, errors.New("Pngquant not compiled in")
}