1

I am using a jimp library to adjust contrast to image and to resize it. for some jpeg files, the original file changed to landscape without any intention. why does it do it and how can I prevent this unwanted file rotation?

async function contrast(file_path, job) {
  const destination = `${received_folder}\\${images}\\${job.regNum}\\${job.recievedName}${job.recievedExtension}`;
  console.log("file path", file_path);
  try {
    const file = await Jimp.read(file_path);
    file.contrast(0.25).resize(Jimp.AUTO, 2000).quality(100).write(destination);

    return true;
  } catch (err) {
    logger.log("error", `optimization failed ${job.regNum} job id ${job.id}. error: ${err.message}`);
    await job.log("error", `the file is damaged. error: ${err.message}`);
    return false;
  }

}

this is how it looks in folder before: before

after: enter image description here

don't mind the file name, it was renamed.

  • 1
    This question is likely related: [How to preserve EXIF data in Jimp when compressing it or using the cover function?](https://stackoverflow.com/q/49115780/691711). JPEG has a rotation metadata piece in the file itself that file explorers will interpret automatically. You may or may not be preserving that EXIF data when you save the adjusted file. – zero298 Jul 22 '21 at 11:47

0 Answers0