Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!