For a personal project, to check how many pictures we took of our cats over the past seven years, I wanted to read EXIF data from my photos. In this blog post I explain how to do it.
library(exifr) library(data.table) library(lubridate)
For exifr to function properly, you need to install perl. A good option is to install the ActivePerl engine — not an expert, but so I was told. For this, you’ll need administrator rights.
You will also need ExifTool, which is written in Perl. There’s several ways you can install Perl:
If Perl or ExifTool isn’t installed, you’ll respectively get one of the following errors:
Could not find perl at any of the following locations…
Could not find ExifTool at any of the following locations…
The function read_exif can take more than one path. You can pass it a vector of paths if you have a folder full of images. We can create that vector as follows:
file_names <- list.files(my_photo_dir) paths <- paste0(my_photo_dir,'/',file_names)
Now, we can finally call on read_exif to read the wanted EXIF tag values from our pictures. If you do not specify which tag you need, it will read all (100+) tags from the picture. In the chunk below I convert the DateTimeOriginal tag to the date the photo was take.
exifs <- read_exif(paths, tags = c('DateTimeOriginal','Model')) exifs <- data.table(exifs) exifs[,Date := ymd(substr(DateTimeOriginal,1,10))]
If you experience any problems, try the exiftoolr package.
By the way, if you’re having trouble understanding some of the code and concepts, I can highly recommend “An Introduction to Statistical Learning: with Applications in R”, which is the must-have data science bible. If you simply need an introduction into R, and less into the Data Science part, I can absolutely recommend this book by Richard Cotton. Hope it helps!