diff options
| author | rmn <r.y.t@yandex.ru> | 2017-05-05 12:17:30 +0300 |
|---|---|---|
| committer | rmn <r.y.t@yandex.ru> | 2017-05-05 12:17:30 +0300 |
| commit | 366fe0d394f7a0ede8cf3d7ef28e574c2f64a0b7 (patch) | |
| tree | d412e8e4fcd356ede4564226673272e997f8fb87 /weed/images/resizing.go | |
| parent | 9fcff1bd9a52b76eef6e1e56d3294b7efdecc439 (diff) | |
| download | seaweedfs-366fe0d394f7a0ede8cf3d7ef28e574c2f64a0b7.tar.xz seaweedfs-366fe0d394f7a0ede8cf3d7ef28e574c2f64a0b7.zip | |
Scale images to fit or fill
Diffstat (limited to 'weed/images/resizing.go')
| -rw-r--r-- | weed/images/resizing.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/weed/images/resizing.go b/weed/images/resizing.go index e644570cb..5af8e45c9 100644 --- a/weed/images/resizing.go +++ b/weed/images/resizing.go @@ -12,7 +12,7 @@ import ( "github.com/disintegration/imaging" ) -func Resized(ext string, data []byte, width, height int) (resized []byte, w int, h int) { +func Resized(ext string, data []byte, width, height int, mode string) (resized []byte, w int, h int) { if width == 0 && height == 0 { return data, 0, 0 } @@ -21,11 +21,18 @@ func Resized(ext string, data []byte, width, height int) (resized []byte, w int, bounds := srcImage.Bounds() var dstImage *image.NRGBA if bounds.Dx() > width && width != 0 || bounds.Dy() > height && height != 0 { - if width == height && bounds.Dx() != bounds.Dy() { - dstImage = imaging.Thumbnail(srcImage, width, height, imaging.Lanczos) - w, h = width, height - } else { - dstImage = imaging.Resize(srcImage, width, height, imaging.Lanczos) + switch mode { + case "fit": + dstImage = imaging.Fit(srcImage, width, height, imaging.Lanczos) + case "fill": + dstImage = imaging.Fill(srcImage, width, height, imaging.Center, imaging.Lanczos) + default: + if width == height && bounds.Dx() != bounds.Dy() { + dstImage = imaging.Thumbnail(srcImage, width, height, imaging.Lanczos) + w, h = width, height + } else { + dstImage = imaging.Resize(srcImage, width, height, imaging.Lanczos) + } } } else { return data, bounds.Dx(), bounds.Dy() |
