Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 24, 2022 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/f55fc0a729b866fad8f8b541f6977953 to your computer and use it in GitHub Desktop.
Save parzibyte/f55fc0a729b866fad8f8b541f6977953 to your computer and use it in GitHub Desktop.
const agregarGloboDeTextoYDevolverBuffer = async (nombreEntrada, porcentaje) => {
const entrada = sharp(nombreEntrada);
const informacionEntrada = await entrada.metadata();
const ALTURA_GLOBO = parseInt((porcentaje * informacionEntrada.height) / 100);
const globo = sharp(NOMBRE_IMAGEN_GLOBO)
.resize({ width: informacionEntrada.width, height: ALTURA_GLOBO, fit: "fill" })
return entrada
.extend({ top: ALTURA_GLOBO, background: { r: 255, g: 255, b: 255, } })
.composite([{ input: await globo.toBuffer(), left: 0, top: 0 }])
.toBuffer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment