mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-15 00:43:21 +07:00
feat: show thumbnails in browser listing, fix object actions overflow
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
_ "image/gif"
|
||||
"image/jpeg"
|
||||
_ "image/png"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
func CreateThumbnailImage(buffer []byte, width uint, height uint) ([]byte, error) {
|
||||
img, _, err := image.Decode(bytes.NewReader(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
thumb := resize.Thumbnail(width, height, img, resize.NearestNeighbor)
|
||||
buf := new(bytes.Buffer)
|
||||
if err := jpeg.Encode(buf, thumb, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user