Sharp: Sharp cuts exif orientation tag by default

Created on 5 Jul 2019  路  4Comments  路  Source: lovell/sharp

That was unobvious why I was getting rotated image after just resizing.

After some investigation, it became clear that this is about EXIF orientation tag in JPEG metadata:

$ exiftool image.jpeg | grep Orientation
Orientation                     : Rotate 180
$ exiftool result.jpeg | grep Orientation
$

Finally, now I know that this can be fixed by using .withMetadata(). But shouldn't orientation metadata tag be included by default?

What is the expected behaviour?
As a user I expected to see just resized image. For example, resizing with ImageMagick provides the correct result.

Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?

const sharp = require('sharp');
const fs = require('fs');

sharp('image.jpeg')
    .resize(200)
    .toBuffer()
    .then( data => {
        fs.writeFileSync('result.jpeg', data);
    })
    .catch( err => {
        console.log(err);
    });

Are you able to provide a sample image that helps explain the problem?
It's funny, also seems like this issue is actual for github as well. Click the preview below and you will see that github's preview is rotated as well. Or maybe github just uses sharp? ;)

sharp_bug_image

question

All 4 comments

Got the same issues, was really confused by it

If you know you will be processing images with EXIF orientation metadata, add a parameter-less rotate() to your pipeline.

https://sharp.pixelplumbing.com/en/stable/api-operation/#rotate

Gottcha, thanks!

Shouldn't there be some more explicit notes on it in Readme.md or in .resize docs?
Cause as I used this library for the first time and needed only to resize an image, how should I understand that I need to go to .rotate docs and read some important info there?

Commit ba46ad1 adds more info on the output methods about the removal of metadata, thanks for the suggestion.

Was this page helpful?
0 / 5 - 0 ratings