On Sun, May 13, 2007 at 01:26:17AM +0900, 12 34 wrote: > Jeremy Hinegardner wrote: > > 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? > >> > > > > 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 > > > Jeremy > I am enjoying. Learned several things with your help. "require" for > example. require is how you pull in other ruby libraries into the current file/program. Libraries must be 'required' before they can be utilized. > And some other nice details about outputting. I got it working > by simplifying the beginning. I didn't understand two lines: > cat exif-test.rb This is a copy and paste of the command line program 'cat' which dumped the contents of hte file 'exif-test.rb' to the terminal/command window. It is a unix command. The equivalent in Windows is 'type'. > or > image_file = ARGV.first > lines. ARGV is a special global Array that holds the other parameters on the command line after the ruby script. So in this case, at the command line I had : ruby exif-test.rb image.jpg ^ ^ ^ | | +--- the image file being processed and first | | element of the ARGV Array. It can be | | accessed via ARGV[0] or ARGV.first | | | +---------------- The ruby program being invoked (accessed as $0) | +--------------------- Invoking the ruby interpreter. > As I changed the script it works for me. But in the interest of > learning. I'm waiting for Black's book before going much further. You may also be interested in Programming Ruby (http://pragmaticprogrammer.com/titles/ruby/index.html) enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy / hinegardner.org