Created
December 7, 2018 17:54
-
-
Save ggomagundan/4a0213fa275dda5435435c3d846449b1 to your computer and use it in GitHub Desktop.
Update Image EXIF Informations
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/ruby | |
# encoding: utf-8 | |
# | |
# Script for changing photo creation timestamp (in EXIF metadata and filesystem) | |
# If you're using rvm, please run script as `ruby photo-touch.rb` | |
# Tested in ruby-2.5.1 | |
# | |
# Install ExifTool: http://www.sno.phy.queensu.ca/~phil/exiftool/install.html | |
# | |
# You need next gems for script to work (use gem install gem_name) | |
# * mini_exiftool (note: you need the ExifTool library!) | |
# | |
# 2018, Kai Park. Use it freely under the MIT license. | |
# | |
require 'rubygems' | |
require 'find' # For Find.find (walk a directory) | |
require 'fileutils' # For FileUtils.touch (change file timestamps) | |
require 'mini_exiftool' # Exif metadata editing | |
require 'date' # For DateTime | |
# Find all jpegs in currrent directory, change timestamps to required | |
Find.find('./') do |f| | |
if f.match(/\.jpg|jpeg|jfif\Z/i) | |
photo = MiniExiftool.new(f) | |
filename = File.basename(f) | |
s_file = filename.split(".")[0].split("_") | |
# B612 NameFormat is follow : | |
# B612_${YYMMDD}_#{HHMMDD}.jpg | |
date = DateTime.parse("#{s_file[1]}T#{s_file[2]}+0900") | |
puts "#{f}\t- #{filename}\t#{date}" # For debug purposes | |
photo.date_time_original = date # Change EXIF photo creation timestamp | |
photo.save | |
# if you wanna update UpdateTime | |
#FileUtils.touch f, :mtime => DateTime.current # Change filesystem creation timestamp | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment