EXIF Library

Hi-

does anyone know of a working EXIF library for Ruby that runs on Windows
and Linux?

So far I’ve tried rexif and ruby-exif without any success.
RMagick (RMagick-1.9.2-IM-6.2.4-6-win32) returns some data, but adds a
‘.’ at the end of every value and undfortunately doesn’t seem to handle
GPSInfo, which contains most of the info I’m interested in.
Thanks for any help,

-markus

Please try EXIFR, http://rubyforge.org/projects/exifr

gem install exifr

It’s a pure ruby EXIF reader so it works on both windows and linux.
Please file a bug in the tracker at rubyforge if GPSInfo is not read
properly/ at all and send me some examples (including the expected
results) since I don’t have any files containing GPSInfo.

Thanks,
Remco

Remco van 't Veer wrote:

Please try EXIFR, http://rubyforge.org/projects/exifr

gem install exifr

It’s a pure ruby EXIF reader so it works on both windows and linux.
Please file a bug in the tracker at rubyforge if GPSInfo is not read
properly/ at all and send me some examples (including the expected
results) since I don’t have any files containing GPSInfo.

Thanks,
Remco

Hi-

thanks for the pointer. Unfortunately it doesn’t work.
I filed a bug report as you suggested.
From a quick glance at the code I couldn’t find any support for GPSInfo
IFD. But then again I’m very new to ruby, actually this was going to be
my first ruby microproject. For the time being I’ve implemented it in
python…

Thanks,

-markus

Just released 0.9.3 with the ability to read GPSInfo.

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?

Thanks for any help.

As a follow on to my Newbie question, here’s what I got when I installed
it

$ sudo gem install exifr
Password:
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed exifr-0.10.2
Installing ri documentation for exifr-0.10.2…
Installing RDoc documentation for exifr-0.10.2…

PS I don’t se an edit for postings. But I guess this is only a window to
Usenet so that wouldn’t work.

Remco van 't Veer wrote:

Please try EXIFR, http://rubyforge.org/projects/exifr

gem install exifr

You may need: sudo gem install exifr

Jeremy H. 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

Running that program on an image

> ruby exif-test.rb 2004120087.JPG
                                Standard items
========================================================================
                          File : 2004120087.JPG
                        Height : 1200
                         Width : 1600

                            EXIF information
=============================================================== <snip-snip long output> 

enjoy,

-jeremy
Jeremy
I am enjoying. Learned several things with your help. “require” for
example. 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
or
image_file = ARGV.first
lines.

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.

Thanks again.

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

Remco van 't Veer wrote:

Please try EXIFR, http://rubyforge.org/projects/exifr

gem install exifr

It’s a pure ruby EXIF reader so it works on both windows and linux.
Please file a bug in the tracker at rubyforge if GPSInfo is not read
properly/ at all and send me some examples (including the expected
results) since I don’t have any files containing GPSInfo.

Thanks,
Remco

Can this be expanded to support RAW images? Specifically MRW
(Konica-Minolta)?

If how would I get into the OS X hooks for handling this? Maybe this
isn’t a Ruby question and I’ll have to go elsewhere. I’m a Newbie to
Ruby (groan), but OS X supports many RAW formats.

I have Appscript, so assume that’s the path, but was hoping to avoid
that for awhile.

Thanks for any clues.

Jeremy H. wrote:

On Sun, May 13, 2007 at 01:26:17AM +0900, 12 34 wrote:

require 'exifr'
puts "Standard items".center(72)
    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
(https://pragprog.com/titles/ruby/programming-ruby-2nd-edition/)

enjoy,

-jeremy

Thanks Jeremy. I have the book and it’s over my head. But Black’s book
arrived today. I ordered it because it is supposed to be a good
intermediate book.

I had looked up all the ARGV refs in Pickaxe and they didn’t make much
sense. I get “require,” but still am learning what needs to be
“required” and what’s built in. I think I can see how ARGV will be
useful, because eventually I’ll be processing all the files in a folder.

I’m running from TextMate in OS X, so wasn’t thinking command line
(which I use infrequently), so I’ll pull in the file paths some other
way.

Much to learn and thanks again.

Since exifr doesn’t support Raw images (see separate posting), I also
have to dig into the hooks to apps in the Mac OS to read the exif for
Raw. But now that I’ve got Black I’ll put some time in with that before
working on my own project too much.

Plus I have to take a vacation to Utah and Colorado in the next two
weeks. Poor me.

12 34 wrote:

I am enjoying. Learned several things with your help. “require” for
example. 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
or
image_file = ARGV.first
lines.

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

If you’re still in the market for a book, check out my review of
“Beginning Ruby” on Slashdot:
Beginning Ruby - Slashdot. I think you’d
find it useful.

On Sun, May 13, 2007 at 01:26:17AM +0900, 12 34 wrote:

require 'exifr'
puts "Standard items".center(72)
    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
(https://pragprog.com/titles/ruby/programming-ruby-2nd-edition/)

enjoy,

-jeremy

On Sun, May 13, 2007 at 08:46:57AM +0900, 12 34 wrote:

(which I use infrequently), so I’ll pull in the file paths some other
way.

You may be interested in using ruby-osa (http://rubyosa.rubyforge.org/)

Much to learn and thanks again.

No worries, have fun and enjoy yourself.

Since exifr doesn’t support Raw images (see separate posting), I also
have to dig into the hooks to apps in the Mac OS to read the exif for
Raw. But now that I’ve got Black I’ll put some time in with that before
working on my own project too much.

That would be cool. Interfacing ruby with CoreImage, you may want to
follow the RubyCocoa project, from their website it says that the
unstable branch supports CoreImage (via QuartzCore),

http://rubycocoa.sourceforge.net/doc/unstable/

I haven’t played with any of these yet, but they do look fun.

Plus I have to take a vacation to Utah and Colorado in the next two
weeks. Poor me.

If you hit anywhere near Boulder, CO I’ll stand you to a beverage of
your choice. If you happen to make here on May 15, the Boulder/Denver
Ruby U. group is meeting.

enjoy,

-jeremy

Jeremy H. wrote:

On Sun, May 13, 2007 at 08:46:57AM +0900, 12 34 wrote:

That would be cool. Interfacing ruby with CoreImage, you may want to
follow the RubyCocoa project, from their website it says that the
unstable branch supports CoreImage (via QuartzCore),

http://rubycocoa.sourceforge.net/doc/unstable/

I haven’t played with any of these yet, but they do look fun.

Plus I have to take a vacation to Utah and Colorado in the next two
weeks. Poor me.

If you hit anywhere near Boulder, CO I’ll stand you to a beverage of
your choice. If you happen to make here on May 15, the Boulder/Denver
Ruby U. group is meeting.

enjoy,

-jeremy

Ruby Cocoa looks like a bit much for me to tackle yet.

How about Telluride? We’re going to the Mountain Film Festival over
Memorial Day Weekend? Beers on me.

On Sun, May 13, 2007 at 01:48:31PM +0900, 12 34 wrote:

How about Telluride? We’re going to the Mountain Film Festival over
Memorial Day Weekend? Beers on me.

Sorry, running the BolderBoulder on Memorial Day. And Telluride is not
exactly near Boulder, its just short 7 hour drive :-).

Oh well, next time.

Enjoy the Film Festival.

-jeremy

On Sun, May 13, 2007 at 02:54:57PM +0900, 12 34 wrote:

I did install RubyCocoa. Will be handy later when I want to put on a
GUI. Is it CoreImage I’d need. I’m not going to change the image or
display it, but I need the meta data. I’ll find out eventually. I think
it’s in Image Events. I just have to figure out the dictionary and how
to write it in Ruby via Appscript.

While looking around for things dealing with this thread, I happened
upon exiv2[1], which is an Exif and IPTC tag reader/writer. And as it
turns out there are ruby bindings to it already. You can use macports
to install the original library and then use gem to install the ruby
bindings[2] to it. The documentation is a little lacking for the ruby
bindings, but it is quite fun too play around with. I’m already
thinking of a few uses for it.

enjoy,

-jeremy

1 - http://www.exiv2.org/
2 - http://rubyforge.org/projects/ruby-exiv2/

Jeremy H. wrote:

On Sun, May 13, 2007 at 01:48:31PM +0900, 12 34 wrote:

How about Telluride? We’re going to the Mountain Film Festival over
Memorial Day Weekend? Beers on me.

Sorry, running the BolderBoulder on Memorial Day. And Telluride is not
exactly near Boulder, its just short 7 hour drive :-).

Oh well, next time.

Enjoy the Film Festival.

-jeremy
Next time. How long is the run? Answered my own question. Looks like a
big event from the web page. Good luck. We’re mountain biking Moab and
Fruita before Telluride and also in Telluride.

I did install RubyCocoa. Will be handy later when I want to put on a
GUI. Is it CoreImage I’d need. I’m not going to change the image or
display it, but I need the meta data. I’ll find out eventually. I think
it’s in Image Events. I just have to figure out the dictionary and how
to write it in Ruby via Appscript.

Jeremy H. wrote:

On Sun, May 13, 2007 at 02:54:57PM +0900, 12 34 wrote:

I did install RubyCocoa. Will be handy later when I want to put on a
GUI.

While looking around for things dealing with this thread, I happened
upon exiv2[1], which is an Exif and IPTC tag reader/writer. And as it
turns out there are ruby bindings to it already. You can use macports
to install the original library and then use gem to install the ruby
bindings[2] to it. The documentation is a little lacking for the ruby
bindings, but it is quite fun too play around with. I’m already
thinking of a few uses for it.

enjoy,

-jeremy

1 - http://www.exiv2.org/
2 - http://rubyforge.org/projects/ruby-exiv2/

I have to use some OS X apps anyway, so I think I’ll try using those via
Appscsript rather than getting more confused trying to use exiv. iMagine
Photo and Image Events are two that come to mind.

But thanks for the suggestion

12 34 wrote:

Can this be expanded to support RAW images? Specifically MRW
(Konica-Minolta)?
Maybe you can use MiniExiftool (http://miniexiftool.rubyforge.org/) wich
can handle (read and write) meta-data of many file formats inclusive
raw-formats such as MRW. :slight_smile:

regards
Jan