From 5603cdd3934e83a5a366710449569438a9b45545 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 4 Jun 2018 17:41:07 +1200 Subject: [PATCH] add compiletime build tag 'disableimagecrush' to remove cgo dependency --- image.go | 4 +--- imagecrush.go | 6 ++++++ imagecrush_disabled.go | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 imagecrush_disabled.go diff --git a/image.go b/image.go index a1648ba..33238cc 100644 --- a/image.go +++ b/image.go @@ -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{} diff --git a/imagecrush.go b/imagecrush.go index f387192..2254af7 100644 --- a/imagecrush.go +++ b/imagecrush.go @@ -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 diff --git a/imagecrush_disabled.go b/imagecrush_disabled.go new file mode 100644 index 0000000..970aeb5 --- /dev/null +++ b/imagecrush_disabled.go @@ -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") +}