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" "bytes"
"image" "image"
"image/jpeg" "image/jpeg"
"code.ivysaur.me/imagequant"
) )
func (this *Thumbnailer) RenderScaledImage(src image.Image) ([]byte, error) { 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 { switch this.ofmt {
case OUTPUT_PNG_CRUSH: case OUTPUT_PNG_CRUSH:
return crush(dest, imagequant.SPEED_FASTEST) return crushFast(dest)
case OUTPUT_JPG: case OUTPUT_JPG:
buff := bytes.Buffer{} buff := bytes.Buffer{}

View File

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