mirror of
				https://github.com/khairul169/garage-webui.git
				synced 2025-10-30 22:59:31 +07:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			493 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			493 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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
 | |
| }
 |