Skip to content

Instantly share code, notes, and snippets.

@adipasquale
Last active December 15, 2022 10:43
Show Gist options
  • Save adipasquale/bf413db581138490b1c9246239165557 to your computer and use it in GitHub Desktop.
Save adipasquale/bf413db581138490b1c9246239165557 to your computer and use it in GitHub Desktop.
How to fix Rails Active Storage thumbnails orientation

If you use Active Storage variants to generate thumbs and your thumbnails are sometimes misoriented, you may have EXIF metadata problems For example:

  • the original image can have an EXIF metadata specifying a 90° rotation
  • when resizing by default libvips will apply this rotation to the pixels
  • HOWEVER it will also preserve the EXIF metadata including this rotation info
  • so the thumbnail is doubly rotated

a solution is to remove all EXIF metadata from the generated thumbs by using saver: { strip: true } in the config:

  has_many_attached :photos do |attachable|
    attachable.variant :medium, resize_to_limit: [800, 800], saver: { strip: true }
  end

this documentation is quite hard to understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment