Skip to content

cowpu2/Exif_Data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Editing EXIF data in photos with R and ExifTool

library(tidyverse)   
library(lubridate)   
library(magrittr)    
library(rprojroot)   
library("tidylog", warn.conflicts = FALSE)  
library(reactable)  
library(reactablefmtr)  
library(exiftoolr)  
library(grateful)  
#configure_exiftoolr(command = "c:/windows/exiftool.exe")  

#Local paths      
base_path    <- find_rstudio_root_file()                        
source_path  <- file.path(base_path, "source_data//")   # my folder is /source_data
# 2022-02-03 19:07:41 ------------------------------mdp  
# 2022-02-07 20:49:09 ------------------------------mdp  

Load data generated by Exiftools

Source file is generated by ExifTool from a batch file. Can be done from command line as well but easier to edit a batch file.

Here's the command - it needs to be in a single line. Watch the ">".

c:\windows\exiftool.exe -csv -common -r G:\\source_data\ >G:\\source_data\Castilleja.csv

I used the default installation for ExifTool so your path to exiftool.exe may be different. Your image folders will be different as well.

# Source file here is output from command line exiftool
Castilleja <- read_csv(paste0(source_path, "Castilleja.csv"))
reactable(Castilleja[1:6], highlight = TRUE, bordered = TRUE, striped = TRUE)

Parse paths/file names

dilbert <- Castilleja %>% separate(SourceFile, c("drive","R", "project",   
                                                 "source","imageSet", "junk"), sep = "/")  
dilbert$junk <- NULL  
dilbert$edited <- "edits"  

reactable(dilbert[1:6], highlight = TRUE, bordered = TRUE, striped = TRUE)  

dilbert <- dilbert %>% unite("inFilePath", 1:5, remove = FALSE, sep = "/") %>%   
                       mutate("inFilePathName" = paste0(inFilePath, "/", FileName)) %>%   
                       unite("editFilePath", inFilePath,   
                                             edited, 
                                             FileName, 
                                             sep = "/", remove = FALSE)

New columns that were created

dilbert$inFilePath[1]
dilbert$inFilePathName[1]
dilbert$edited[1]
dilbert$editFilePath[1]

Pull out a selection of files based on camera model

edits <- dilbert %>% filter(Model == "SM-G950U") %>% 
  select(-c(drive, R, project, source, imageSet, FileSize, Model, ImageSize, Quality, FocalLength, ShutterSpeed, Aperture, ISO, WhiteBalance, Flash))

reactable(edits[1:5,], highlight = TRUE, bordered = TRUE, striped = TRUE)

Create a new folder

This is really just for grins and giggles - it isn't necessary

FromName <- edits$inFilePathName
ToName <-  paste0(edits$editFilePath)

folder <- "source_data/Castilleja/edits"

if (file.exists(folder)) {

 cat("The folder already exists")

} else {

 dir.create(folder)

}

Move selected files to new folder

file.rename(FromName, ToName)

Create and write new timestamps to the images

Exiftool creates a copy of the all the files and renames them prior to making any changes

Edits_df <- edits %>% mutate("newDateTime" = "5:0:11 0:0:0")

exif_call(args =  Edits_df$editFilePath, paste0("-DateTimeOriginal+=", Edits_df$newDateTime))

dogbert <- exif_read(Edits_df$editFilePath) %>% 
  select(FileName, Model, ModifyDate, DateTimeOriginal)

Did it work?

reactable(dogbert, highlight = TRUE, bordered = TRUE, striped = TRUE) %>% 
  add_title("FileName & ModifyDate are the same") %>% 
  add_subtitle("We added 5 years 11 days to DateTimeOriginal") %>% 
  add_source("We should have paid closer attention - the date on the first file doesn't line up with the rest")


Automagically generate citations from packages used - see html file Exif.html

References

cite <- cite_packages(cite.tidyverse = TRUE, output="paragraph")

#cite <- get_citations(scan_packages())

cite

About

Editing EXIF data in photos with R and ExifTool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published