From: Daniel Berger Date: 2007-07-19T22:06:47+09:00 Subject: Re: Validating an Image file is an image file On Jul 19, 5:05 am, "Raf Coremans" wrote: > 2007/7/18, Daniel Berger : > > > > def self.jpg?(file) > > IO.read(file, 10) == "\377\330\377\340\000\020JFIF" && > > File.extname(file).downcase == '.jpg' > > end > > Ack! The proper abbreviation, and thus also the filename extension, is > 'jpeg'. 'jpg' is an abomination introduced by the same people who introduced > the *shudder* '.htm' filename extension. Be that as it may, you will see both extensions in practice. So, the code should probably be refactored to be: def self.jpeg?(file) IO.read(file, 10) == "\377\330\377\340\000\020JFIF" && ['.jpg', '.jpeg'].include?(File.extname(file).downcase) end alias jpg? jpeg? Regards, Dan