0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Active Storageで画像サイズ(縦幅、横幅)を取得する

Posted at

モデル

class Foo < ApplicationRecord
  has_one_attached :image
end

取得

f = Foo.first

f.image.metadata[:height] # 縦幅
f.image.metadata[:width]  # 横幅

注意点

metadataへの登録は非同期で行われるため、レコード保存直後はデータが入っていない可能性があります。参考

  • analyze前
{"identified"=>true}
  • analyze後
{"identified"=>true, "width"=>320, "height"=>150, "analyzed"=>true}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?