class Geotagger::Image

Wrapper class for path to image and the EXIF data read (and written) to the image.

Attributes

attr[R]
editor[R]
photo[R]

Public Class Methods

new(editor, path, time_offset = 0) click to toggle source
# File lib/geotagger/exif_editor.rb, line 14
def initialize(editor, path, time_offset = 0)
  @editor = editor
  @photo = MiniExiftool.new path
  @attr = {
   :path => path,
   :time => (time = @photo['DateTimeOriginal']) && (time + time_offset + editor.global_time_offset)
  }
end

Public Instance Methods

[](key) click to toggle source
# File lib/geotagger/exif_editor.rb, line 31
def [](key)
  @attr[key]
end
[]=(key,value) click to toggle source
# File lib/geotagger/exif_editor.rb, line 35
def []=(key,value)
  @attr[key] = value
end
get_photo_time(offset=0) click to toggle source
# File lib/geotagger/exif_editor.rb, line 39
def get_photo_time(offset=0)
  (time = photo['DateTimeOriginal']) && (time + offset)
end
path() click to toggle source
# File lib/geotagger/exif_editor.rb, line 23
def path
  self[:path]
end
save!() click to toggle source
# File lib/geotagger/exif_editor.rb, line 43
def save!
  # http://en.wikipedia.org/wiki/Geotagging#JPEG_photos

  photo['ProcessingSoftware'] = 'gpx2exif'

  photo['GPSVersionID'] = '2 2 0 0'
  photo['DateTimeOriginal'] = self.time

  photo['GPSLatitude'] = @attr[:coord][:lat]
  photo['GPSLongitude'] = @attr[:coord][:lon]

  lat_ref = (@attr[:coord][:lat] < 0.0) ? "S" : "N"
  lon_ref = (@attr[:coord][:lon] < 0.0) ? "W" : "E"

  photo['GPSLatitudeRef'] = lat_ref
  photo['GPSLongitudeRef'] = lon_ref

  photo['GPSAltitude'] = @attr[:coord][:alt]
  photo['Orientation'] = 1  # 1 means normal upright landscape mode
  photo['GPSImgDirectionRef'] = 'T' # T=true north (as opposed to M=magnetic)
  photo['GPSImgDirection'] = @attr[:coord][:direction]      # calculated in TrackImporter
  photo['GPSMapDatum'] = 'WGS-84'   # We assume all GPS data is WGS-84

  (editor.options[:exif_tags]||{}).each do |key,value|
    photo[key] = value
  end

  unless photo.save
    puts "Failed to save exif data to '#{path}': #{photo.errors.inspect}"
  end

  photo2 = MiniExiftool.new path
  puts " - coord saved lat #{photo2['GPSLatitude']} lon #{photo2['GPSLongitude']}" if editor.verbose

  # exiftool -GPSMapDatum="WGS-84" -gps:GPSLatitude="34,57,57"
  # -gps:GPSLatitudeRef="N" -gps:GPSLongitude="83,17,59" -gps:GPSLongitudeRef="W"
  # -gps:GPSAltitudeRef="0" -GPSAltitude=1426 -gps:GPSMeasureMode=2 -City="RabunBald"
  # -State="North Carolina" -Country="USA" ~/Desktop/RabunBaldSummit_NC.jpg
end
time() click to toggle source
# File lib/geotagger/exif_editor.rb, line 27
def time
  self[:time]
end
to_s() click to toggle source
# File lib/geotagger/exif_editor.rb, line 83
def to_s
  "Image[#{path}] at '#{time}'"
end