Last active
April 10, 2025 19:22
-
-
Save Klerith/a305490953d130928afa87257e47d432 to your computer and use it in GitHub Desktop.
Descargar imagen base 64
This file contains hidden or 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
export const downloadBase64ImageAsPng = async (base64Image: string) => { | |
// Remover encabezado | |
base64Image = base64Image.split(';base64,').pop(); | |
const imageBuffer = Buffer.from(base64Image, 'base64'); | |
const folderPath = path.resolve('./', './generated/images/'); | |
fs.mkdirSync(folderPath, { recursive: true }); | |
const imageNamePng = `${ new Date().getTime() }-64.png`; | |
// Transformar a RGBA, png // Así lo espera OpenAI | |
await sharp(imageBuffer) | |
.png() | |
.ensureAlpha() | |
.toFile(path.join(folderPath, imageNamePng)); | |
return path.join(folderPath, imageNamePng); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias profesor!!