Permalink
Browse files

jpeg: added gps_lat/gps_lng methods for converting lat/lng to decimal…

…s. added gps method to return lat/lng in array. all accompanied by tests. added ruby env declaration to /bin/exifr
  • Loading branch information...
soychicka committed May 2, 2010
1 parent 4635657 commit 6418ac12d54fc79aaeb96fccda052b8f697d99e4
Showing with 38 additions and 1 deletion.
  1. +2 −0 bin/exifr
  2. +12 −0 lib/jpeg.rb
  3. BIN tests/data/iPhone-gps.jpg
  4. +24 −1 tests/jpeg_test.rb
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
require 'exifr'
include EXIFR
@@ -48,7 +48,19 @@ def to_hash
h.merge!(exif) if exif?
h
end
def gps
[self.gps_lat, self.gps_lng]
end
def gps_lat
self.gps_latitude[0].to_f+self.gps_latitude[1].to_f/60+self.gps_latitude[2].to_f/3600
end
def gps_lng
self.gps_longitude[0].to_f+self.gps_longitude[1].to_f/60+self.gps_longitude[2].to_f/3600
end
# Dispatch to EXIF. When no EXIF data is available but the
# +method+ does exist for EXIF data +nil+ will be returned.
def method_missing(method, *args)
Binary file not shown.
@@ -65,10 +65,33 @@ def test_exif_dispatch
assert j.respond_to?('date_time')
assert_not_nil j.date_time
assert_kind_of Time, j.date_time
assert_not_nil j.f_number
assert_kind_of Rational, j.f_number
end
def test_geolocation
j = JPEG.new(f('iPhone-gps.jpg'))
assert j.methods.include?('gps_latitude')
assert j.gps_latitude[0].to_f ==37.0
assert j.gps_latitude[1].to_f ==46.0
assert j.gps_latitude[2].to_f ==43.024
assert j.methods.include?('gps_longitude')
assert j.gps_longitude[0].to_f ==122.0
assert j.gps_longitude[1].to_f ==26.0
assert j.gps_longitude[2].to_f ==20.211
assert j.methods.include?('gps_lat')
assert j.methods.include?('gps_lng')
assert j.gps_lat.to_s == '37.7786177777778'
assert j.gps_lng.to_s == '122.4389475'
assert j.methods.include?('gps')
gps=j.gps
assert j.gps[0].to_s == '37.7786177777778'
assert j.gps[1].to_s == '122.4389475'
end
def test_no_method_error
assert_nothing_raised { JPEG.new(f('image.jpg')).f_number }

0 comments on commit 6418ac1

Please sign in to comment.