RubyFlow The Ruby and Rails community linklog

ActiveStorage variants are persisting original image EXIF metadata

Imagine you are using Rails 5.2 ActiveStorage. Now you upload an image, render it with app.url_for my_model.image.variant(resize: '400x300') and discover that it’s rotated 90 deg to you would normally expect. You copy paste the link to the image to the browser and discover the image is rotated correctly. How is that possible?

This is due to the fact that original image may have had EXIF rotation image metadata (e.g. if photo taken from iPhone, and rotation was done) ActiveStorage does nothing to the original EXIF metadata. Now this is not a bad thing but if you discover this being an issue try app.url_for my_model.image.variant(resize: '400x300, auto_orient: true') (auto_orient will remove the EXIF while rendering the variant)

If you want to learn more read my ticket on Rails Active Storage related to this https://github.com/rails/rails/issues/35028

hope it will save you few hours of debugging

Comments

Thank you for this, you’ve saved me hours of debugging

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in