Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active April 10, 2025 19:22
Show Gist options
  • Save Klerith/a305490953d130928afa87257e47d432 to your computer and use it in GitHub Desktop.
Save Klerith/a305490953d130928afa87257e47d432 to your computer and use it in GitHub Desktop.
Descargar imagen base 64
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);
}
@m01x
Copy link

m01x commented Mar 16, 2025

Gracias profesor!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment