|
|
@ -11,6 +11,11 @@ import ( |
|
|
"github.com/disintegration/imaging" |
|
|
"github.com/disintegration/imaging" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const defaultJpegQuality = 85 |
|
|
|
|
|
|
|
|
|
|
|
// TODO resize image with vipsthumbnail
|
|
|
|
|
|
// use `/dev/shm` as memory file system
|
|
|
|
|
|
|
|
|
func Resized(ext string, data []byte, width, height int) (resized []byte, w int, h int) { |
|
|
func Resized(ext string, data []byte, width, height int) (resized []byte, w int, h int) { |
|
|
if width == 0 && height == 0 { |
|
|
if width == 0 && height == 0 { |
|
|
return data, 0, 0 |
|
|
return data, 0, 0 |
|
|
@ -34,7 +39,7 @@ func Resized(ext string, data []byte, width, height int) (resized []byte, w int, |
|
|
case ".png": |
|
|
case ".png": |
|
|
png.Encode(&buf, dstImage) |
|
|
png.Encode(&buf, dstImage) |
|
|
case ".jpg", ".jpeg": |
|
|
case ".jpg", ".jpeg": |
|
|
jpeg.Encode(&buf, dstImage, nil) |
|
|
|
|
|
|
|
|
jpeg.Encode(&buf, dstImage, &jpeg.Options{Quality: defaultJpegQuality}) |
|
|
case ".gif": |
|
|
case ".gif": |
|
|
gif.Encode(&buf, dstImage, nil) |
|
|
gif.Encode(&buf, dstImage, nil) |
|
|
} |
|
|
} |
|
|
|