From: Daniel Berger Date: 2007-07-19T23:10:37+09:00 Subject: Re: Validating an Image file is an image file On Jul 19, 7:06 am, Daniel Berger wrote: > 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? Whoops, that should be: class << self alias jpg? jpeg? end Regards, Dan