Test If A Filename Is An Image Or Not
Join the DZone community and get the full member experience.Join For Free
This function returns true if a file is an image file. Of course it contains the usual suspects for image files, adding others is an exercise to the reader.
def is_image?(filename) ['.png','.jpg','jpeg','.gif','.bmp'].include? filename[-4,4].downcase end
Opinions expressed by DZone contributors are their own.