Rails ActiveStorage is automatically storing width/height of image
When reading ActiveStorage Overview Guild chances are you missed section on #analyze which claims:
New blobs are automatically and asynchronously analyzed via analyze_later when they're attached for the first time.
That means Given model like this:
class Image < ApplicationRecord
has_one_attached :file
end
…you can access your image dimensions with:
image.file.metadata
#=> {"identified"=>true, "width"=>2448, "height"=>3264, "analyzed"=>true}
image.file.metadata['width']
image.file.metadata['height']
More info in this article
https://blog.eq8.eu/til/image-width-and-height-in-rails-activestorage.html
Post a comment