Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created June 30, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/9fbc61900ca1a907f825 to your computer and use it in GitHub Desktop.
Save whatalnk/9fbc61900ca1a907f825 to your computer and use it in GitHub Desktop.
Edit Exif data (change date taken)
require 'mini_exiftool'
# modified mini_exiftool/examples/shift_time.rb
# MiniExiftool.command = 'path/to/exiftool.exe'
delta = 60*60*2 # 2 hour
# Dir.chdir("./path/to/photos") do
Dir.foreach(".") do |f|
if f =~ /.+\.JPG$/ then
begin
photo = MiniExiftool.new(f)
rescue MiniExiftool::Error => e
$stderr.puts e.message
exit -1
end
org_time = photo['DateTimeOriginal']
photo['DateTimeOriginal'] = org_time + delta
saved = photo.save
if saved then
fmt = '%Y-%m-%d %H:%M:%S'
puts "#{f} changed: #{org_time.strftime(fmt)} -> #{photo['DateTimeOriginal'].strftime(fmt)}"
else
puts "#{f} could not be changed"
end
end
end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment