Ruby on Rails: How do you check if a file is an image?

后端 未结 6 1838
醉酒成梦
醉酒成梦 2020-12-28 17:02

How would you check if a file is an image? I\'m thinking you could use an method like so:

def image?(file)
  file.to_s.include?(\".gif\") or file.to_s.includ         


        
6条回答
  •  再見小時候
    2020-12-28 17:51

    imagemagick has a command called identity that handles this - check w/ the paperclip documentation - there's probably a way to handle this from within your RoR app.

提交回复
热议问题