Skip to content

Commit

Permalink
jpeg: added gps_lat/gps_lng methods for converting lat/lng to decimal…
Browse files Browse the repository at this point in the history
…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 6418ac1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/exifr
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby

require 'exifr' require 'exifr'
include EXIFR include EXIFR


Expand Down
12 changes: 12 additions & 0 deletions lib/jpeg.rb
Expand Up @@ -48,7 +48,19 @@ def to_hash
h.merge!(exif) if exif? h.merge!(exif) if exif?
h h
end 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 # Dispatch to EXIF. When no EXIF data is available but the
# +method+ does exist for EXIF data +nil+ will be returned. # +method+ does exist for EXIF data +nil+ will be returned.
def method_missing(method, *args) def method_missing(method, *args)
Expand Down
Binary file added tests/data/iPhone-gps.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion tests/jpeg_test.rb
Expand Up @@ -65,10 +65,33 @@ def test_exif_dispatch
assert j.respond_to?('date_time') assert j.respond_to?('date_time')
assert_not_nil j.date_time assert_not_nil j.date_time
assert_kind_of Time, j.date_time assert_kind_of Time, j.date_time

assert_not_nil j.f_number assert_not_nil j.f_number
assert_kind_of Rational, j.f_number assert_kind_of Rational, j.f_number
end 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 def test_no_method_error
assert_nothing_raised { JPEG.new(f('image.jpg')).f_number } assert_nothing_raised { JPEG.new(f('image.jpg')).f_number }
Expand Down

0 comments on commit 6418ac1

Please sign in to comment.