Sharp: Rotation issue?

Created on 17 Apr 2018  路  6Comments  路  Source: lovell/sharp

Hey there!

Should auto rotate fix this?
wrong-tiff

I'm currently using the .rotate() method to kinda auto-rotate the images for me (tested also without it)... but I recently stumbled on this picture that it isn't working as expected (end-user perspective) the output is always the same. I tested uploading this photo in popular social networks to see how they handled it and for example... facebook and gmail handles it ok but some of othersites don't.

Any idea on how to handle this situation correctly?

ps: I'm currently on sharp v0.19.1.

question

Most helpful comment

@lovell I think I found the problem. Apparently, the toBuffer() is erasing the EXIF orientation. I added a .withMetadata() before the toBuffer() and it handled it nicely. Is this the expected behaviour?

All 6 comments

Hello, this image autorotates correctly for me on v0.20.1 using its EXIF orientation value of 6. Please can you check the latest version and if that's still causing problems share the exact code that fails.

@lovell I think I found the problem. Apparently, the toBuffer() is erasing the EXIF orientation. I added a .withMetadata() before the toBuffer() and it handled it nicely. Is this the expected behaviour?

I know it's weird but yeah, a single image passes through a few toBuffer's during the process.

"The default behaviour, when withMetadata is not used, is to strip all metadata" http://sharp.pixelplumbing.com/en/stable/api-output/#withmetadata

@lovell Oh! Sorry @lovell I missed that on the docs. All good.

@lovell I appreciate all the help.

Was this page helpful?
0 / 5 - 0 ratings