You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
482 B

package main
import (
"bytes"
"fmt"
"image"
"image/jpeg"
"image/png"
)
func dataToImage(data []byte, imageExtension string) (image.Image, error) {
reader := bytes.NewReader(data)
//img, err := png.Decode(reader)
var img image.Image
var err error
switch imageExtension {
case "png":
img, err = png.Decode(reader)
case "jpg", "jpeg":
img, err = jpeg.Decode(reader)
default:
img = nil
}
if err != nil {
fmt.Println(err)
return img, err
}
return img, err
}