From: Jeremy Hinegardner Date: 2007-05-12T14:35:20+09:00 Subject: Re: EXIF Library On Sat, May 12, 2007 at 11:44:53AM +0900, 12 34 wrote: > Newbie here. What's the syntax to read say the date and time the picture > was taken? > > I tried: > > puts EXIFR::JPEG.new("/file/is/here/tests/data/exif.jpg").date_time > > and got: NameError: uninitialized constant EXIFR > > Maybe I didn't get it installed right? Install exifr with : sudo gem install exifr Example program to display exif tags. > cat exif-test.rb require 'rubygems' require 'exifr' image_file = ARGV.first exif_info = nil case image_file.downcase when /.jpg\Z/ exif_info = EXIFR::JPEG.new(image_file) when /.tiff?\Z/ exif_info = EXIFR::TIFF.new(image_file) end puts "Standard items".center(72) puts "=" * 72 puts " File : #{image_file}" puts " Height : #{exif_info.height}" puts " Width : #{exif_info.width}" puts if exif_info.exif? then puts "EXIF information".center(72) puts "=" * 72 h = exif_info.exif.to_hash h.each_pair do |k,v| puts "#{k.to_s.rjust(30)} : #{v}" end else puts "No EXIF information in this image" end Running that program on an image > ruby exif-test.rb 2004120087.JPG Standard items ======================================================================== File : 2004120087.JPG Height : 1200 Width : 1600 EXIF information ======================================================================== exposure_mode : 1 shutter_speed_value : 117/16 exposure_time : 1/160 orientation : EXIFR::TIFF::TopLeftOrientation sensing_method : 2 color_space : 1 metering_mode : 2 x_resolution : 180 white_balance : 0 focal_plane_x_resolution : 100000/13 aperture_value : 95/32 f_number : 14/5 pixel_x_dimension : 1600 date_time_original : Thu Dec 30 12:02:53 -0700 2004 y_resolution : 180 resolution_unit : 2 digital_zoom_ratio : 1 focal_plane_y_resolution : 100000/13 ycb_cr_positioning : 1 pixel_y_dimension : 1200 flash : 16 date_time_digitized : Thu Dec 30 12:02:53 -0700 2004 make : Canon focal_plane_resolution_unit : 2 exposure_bias_value : 4294967291/3 focal_length : 173/32 model : Canon PowerShot SD100 scene_capture_type : 0 max_aperture_value : 95/32 custom_rendered : 0 compressed_bits_per_pixel : 3 date_time : Thu Dec 30 12:02:53 -0700 2004 enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org