mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
image transformation improvements
- switch to disintegration/imaging library, which supports more of the transformations I want to add - pass image through untouched if provided Options are empty
This commit is contained in:
parent
fde104a7a1
commit
805aa606ca
1 changed files with 6 additions and 3 deletions
|
@ -7,14 +7,17 @@ import (
|
||||||
"image/gif"
|
"image/gif"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/nfnt/resize"
|
"github.com/disintegration/imaging"
|
||||||
"github.com/willnorris/go-imageproxy/data"
|
"github.com/willnorris/go-imageproxy/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var emptyOptions = new(data.Options)
|
||||||
|
|
||||||
// Transform the provided image.
|
// Transform the provided image.
|
||||||
func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
||||||
if opt == nil {
|
if opt == nil || reflect.DeepEqual(opt, emptyOptions) {
|
||||||
return &img, nil
|
return &img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +29,7 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
||||||
|
|
||||||
// resize
|
// resize
|
||||||
if opt.Width != 0 || opt.Height != 0 {
|
if opt.Width != 0 || opt.Height != 0 {
|
||||||
m = resize.Resize(uint(opt.Width), uint(opt.Height), m, resize.Lanczos3)
|
m = imaging.Fit(m, opt.Width, opt.Height, imaging.Lanczos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode image
|
// encode image
|
||||||
|
|
Loading…
Reference in a new issue