-
-
Save parzibyte/394bf004aebbd83e9aa509521c1f5474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Recibe una cadena en base64 y devuelve un image.Image | |
Si la cadena inicia con algo como data:image/png;base64, entonces será removido | |
*/ | |
func convertirBase64AImagen(imagenCodificadaEnBase64 string) (image.Image, error) { | |
marca := ";base64," | |
indice := strings.Index(imagenCodificadaEnBase64, marca) | |
if indice != -1 { | |
imagenCodificadaEnBase64 = imagenCodificadaEnBase64[indice+len(marca):] | |
} | |
decodificado, err := base64.StdEncoding.DecodeString(imagenCodificadaEnBase64) | |
if err != nil { | |
return nil, err | |
} | |
imagen, _, err := image.Decode(bytes.NewReader(decodificado)) | |
return imagen, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment