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

277
Vistas
Rotating image without increasing file size (Sharp/Node)

I'm trying to rotate images on my computer using Sharp and Nodejs but every single rotation causes a small increase to the file size, to the point I've got one image 10x the size of its original (from 50kb to 500kb) just by rotating it.

I've noticed there are similar questions on stackoverflow but they all seem to have a solution related to the tech stack being used and I can't find anything related to this with sharp/node.

Perhaps the solution has to do with lossy encoding, I'm not sure, but my goal is to rotate images like the Photos app on windows which is able to rotate without increasing file size, or at least the original file size is restored when the image is rotated to its original orientation.

The code being used is pretty straightforward:

await sharp(filepath).rotate(90).toFile(output, rotateImgCallback);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Thank you @RobertKawecki for the insight that I needed. I tried grabbing the input images orientation with:

let imgPromise = sharp(filepath);
const { orientation } = await imgPromise.metadata();

then calculating the new orientation accordingly and setting it with:

await imgPromise.withMetadata({
        orientation: newOrientation
      }).toFile(output, rotateImgCallback);

without any rotate operation

This works great on jpeg but now I found out pngs don't use exif orientation so I have to figure something out for that as well.

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