Class: Geotagger::ExifEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/geotagger/exif_editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ExifEditor

Returns a new instance of ExifEditor.



93
94
95
96
97
98
99
# File 'lib/geotagger/exif_editor.rb', line 93

def initialize(options = {})
  @options = options
  @images = []
  @image_map = {}
  @global_time_offset = 0
  @verbose = options[:verbose]
end

Instance Attribute Details

#global_time_offsetObject

Returns the value of attribute global_time_offset.



102
103
104
# File 'lib/geotagger/exif_editor.rb', line 102

def global_time_offset
  @global_time_offset
end

#imagesObject (readonly)

Returns the value of attribute images.



101
102
103
# File 'lib/geotagger/exif_editor.rb', line 101

def images
  @images
end

#optionsObject (readonly)

Returns the value of attribute options.



91
92
93
# File 'lib/geotagger/exif_editor.rb', line 91

def options
  @options
end

#verboseObject (readonly)

Returns the value of attribute verbose.



91
92
93
# File 'lib/geotagger/exif_editor.rb', line 91

def verbose
  @verbose
end

Instance Method Details

#fix_timesObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/geotagger/exif_editor.rb', line 104

def fix_times
  start_time = options[:start_time] && DateTime.parse(options[:start_time]) || DateTime.now
  puts "Start: #{start_time}"
  @images.each_with_index do |image,index|
    if image[:time].nil?
      timestamp = start_time + ((options[:time_gap] || 1000).to_i * index) / (1000.0 * 24 * 60 * 60)
      image[:time] = timestamp.to_time
    end
    puts "#{index}: #{image.attr.inspect}"
  end
end

#get_photo_time(path) ⇒ Object



124
125
126
127
# File 'lib/geotagger/exif_editor.rb', line 124

def get_photo_time(path)
  image = @image_map[path] || read_file(path)
  image.photo['DateTimeOriginal']
end

#read_file(path, time_offset = 0) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/geotagger/exif_editor.rb', line 116

def read_file(path, time_offset = 0)
  image = Image.new(self,path,time_offset)
  @images << image
  @image_map[path] = image
  puts "Added #{image}" if @verbose
  image
end