Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
Overlay with opacity setting using Sharp

I'd like to take one image and composite it on top of another image.

This works well for that purpose:

overlayImg = await Sharp(sourceImage.Body)
            .composite([{ 
                input: './lambdas/processNewImage/logos/white.png', 
                gravity: 'southeast',
                
            }])
            .toFormat('jpeg').toBuffer();

I also have a variable - 1-100 that is supposed to be the opacity of the watermark. Sometimes I want it full solid At 100% opacity, others 70% and others 30%...etc. Because I need this to be variable, I cannot just change the opacity of the watermark image.

I cannot figure out how to change the opacity of a composited image in Sharp.

Can any one give a quick example?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found this in another thread where you overlay with a raw pixel buffer containing tiled, semi-transparent pixel value. 128 means 50% opacity where valid values are 0-255. https://github.com/lovell/sharp/issues/554

overlayImg = await Sharp(sourceImage.Body)
  .composite([
    { 
      input: './lambdas/processNewImage/logos/white.png', 
      gravity: 'southeast',  
    },
    {
      input: Buffer.from([0,0,0,128]),
      raw: {
        width: 1,
        height: 1,
        channels: 4,
      },
      tile: true,
      blend: 'dest-in',
    }
  ])
  .toFormat('jpeg').toBuffer();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda