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.include?(".png") or file.to_s.include?(".jpg")
end
But that might be a little inefficient and not correct. Any ideas?
(I'm using the paperclip plugin, btw, but I don't see any methods to determine whether a file is an image in paperclip)
I would use the ruby-filemagic gem which is a Ruby binding for libmagic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With