[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: EXIF Library

12 34

5/12/2007 2:45:00 AM

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.

--
Posted via http://www.ruby-....

14 Answers

Jeremy Hinegardner

5/12/2007 5:35:00 AM

0

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


12 34

5/12/2007 4:26:00 PM

0

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

--
Posted via http://www.ruby-....

Jeremy Hinegardner

5/12/2007 10:57:00 PM

0

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/...)

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org


12 34

5/12/2007 11:47:00 PM

0

Jeremy Hinegardner 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
> (http://pragmaticprogrammer.com/titles/ruby/...)
>
> 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.

--
Posted via http://www.ruby-....

Tim Hunter

5/12/2007 11:53:00 PM

0

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:
http://books.slashdot.org/article.pl?sid=07/04/.... I think you'd
find it useful.

--
RMagick [http://rmagick.rub...]
RMagick Installation FAQ [http://rmagick.rub.../install-faq.html]


Jeremy Hinegardner

5/13/2007 12:17:00 AM

0

On Sun, May 13, 2007 at 08:46:57AM +0900, 12 34 wrote:
> 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.

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

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

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 Users group is meeting.

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org


12 34

5/13/2007 4:49:00 AM

0

Jeremy Hinegardner 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...
>
> 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 Users 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.

--
Posted via http://www.ruby-....

Jeremy Hinegardner

5/13/2007 5:14:00 AM

0

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

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org


12 34

5/13/2007 5:55:00 AM

0

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

--
Posted via http://www.ruby-....

Jeremy Hinegardner

5/13/2007 9:51:00 AM

0

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....
2 - http://rubyforge.org/projects/r...

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org