Created
April 12, 2016 21:49
-
-
Save alext/d75c230c7de61ffb81000362d4b94290 to your computer and use it in GitHub Desktop.
Script to adjust the EXIF date of an image file by a given offset in days.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
require 'time' | |
EXIF_DATE_FORMAT='%Y:%m:%d %H:%M:%S' | |
offset = ARGV[0].to_i | |
file_name = ARGV[1] | |
raise "Can't find file #{file_name}" unless File.exist?(file_name) | |
file_date, status = Open3.capture2('exiftool', '-p', '$DateTimeOriginal', file_name) | |
raise "Failed to read date" unless status.success? | |
file_date.strip! | |
date = DateTime.strptime(file_date, EXIF_DATE_FORMAT) | |
new_date = (date + offset).strftime(EXIF_DATE_FORMAT) | |
puts "#{file_name}: #{file_date} => #{new_date}" | |
output, status = Open3.capture2e('exiftool', "-DateTimeOriginal=#{new_date}", "-CreateDate=#{new_date}", "-ModifyDate=#{new_date}", file_name) | |
raise "Failed to set dates: #{output}" unless status.success? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment