Is there a simple way to get image dimensions in Ruby?

前端 未结 8 946
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 06:57

I\'m looking for an easy way to get width and height dimensions for image files in Ruby without having to use ImageMagick or ImageScience (running Snow Leapard).

8条回答
  •  时光取名叫无心
    2020-12-14 07:28

    There's also a new (July 2011) library that wasn't around at the time the question was originally asked: the Dimensions rubygem (which seems to be authored by the same Sam Stephenson responsible for the byte-manipulation techniques also suggested here.)

    Below code sample from project's README

    require 'dimensions'
    
    Dimensions.dimensions("upload_bird.jpg")  # => [300, 225]
    Dimensions.width("upload_bird.jpg")       # => 300
    Dimensions.height("upload_bird.jpg")      # => 225
    

提交回复
热议问题