Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda