Chris Warwick, @cjwarwickps, November 2015
The EXIF DateTaken property ('ExifDT', metadata property id 36867) is typical written to image files when the file is acquired (by a camera for example). The value can be used to create image file names based on the DateTaken - to allow for easy sorting and categorisation.
In addition to reading the DateTaken value it can also be useful in certain circumstances to modify the value within the file. Two examples might be:
-
When the date in the image is incorrect (when the camera clock was wrong, perhaps because it wasn't adjusted for daylight time or when travelling across time zones).
-
When gathering collections of event photos from several contributors and merging them into a single set; in this case it is likely that the times from multiple cameras will need to be synchronised so the resulting photos can be sorted into accurate chronological sequence.
Tip: If merging photos from several cameras, an effective trick is to take a photo of a common clock or watch, so a relative time offset for each camera can be easily calculated.
The module contains two functions:
Get-ExifDateTaken -Path <filepaths>
Takes a file (fileinfo or string) or an array of these
Gets the ExifDT value (EXIF Property 36867)
Update-ExifDateTaken -Path <filepaths> -Offset <TimeSpan>
Takes a file (fileinfo or string) or an array of these
Modifies the ExifDT value (EXIF Property 36867) as specified
gci *.jpg |
Get-ExifDateTaken |
Rename-Item -NewName {"Holiday Snap {0:MM-dd HH.mm.ss dddd} ({1}).jpg" -f $_.ExifDateTaken, (Split-Path (Split-Path $_) -Leaf)}
gci *.jpg|Update-ExifDateTaken -Offset '-0:07:10' -PassThru|ft Path, ExifDateTaken
gci *.jpg |
Update-ExifDateTaken -Offset '-0:07:10' -PassThru |
Rename-Item -NewName {"Holiday Snap {0:MM-dd HH.mm.ss dddd} ({1}).jpg" -f $_.ExifDateTaken, (Split-Path (Split-Path $_) -Leaf)}
<#
.Synopsis
Gets the DateTaken EXIF property in an image file.
.Description
This cmdlet reads the EXIF DateTaken property in an image and passes is down the pipeline
attached to the PathInfo item of the image file.
.Parameter Path
The image file or files to process.
.Example
Get-ExifDateTaken img3.jpg
Reads the img3.jpg file and returns the im3.jpg PathInfo item with the EXIF DateTaken attached
.Example
Get-ExifDateTaken *3.jpg |ft path, exifdatetaken
Output the EXIF DateTaken values for all matching files in the current folder
.Example
gci *.jpeg,*.jpg|Get-ExifDateTaken
Read multiple files from the pipeline
.Example
gci *.jpg|Get-ExifDateTaken|Rename-Item -NewName {"Holiday Snap {0:MM-dd HH.mm.ss}.jpg" -f $_.ExifDateTaken}
Gets the EXIF DateTaken on multiple files and renames the files based on the time
.Outputs
The scripcmdlet outputs FileInfo objects with an additional ExifDateTaken
property that can be used for later processing.
.Functionality
Gets the EXIF DateTaken image property on a specified image file.
#>
<#
.Synopsis
Changes the DateTaken EXIF property in an image file.
.Description
This cmdlet updates the EXIF DateTaken property in an image by adding an offset to the
existing DateTaken value. The offset (which must be able to be interpreted as a [TimeSpan] type)
can be positive or negative - moving the DateTaken value to a later or earlier time, respectively.
This can be useful (for example) to correct times where the camera clock was wrong for some reason -
perhaps because of timezones; or to synchronise photo times from different cameras.
.Parameter Path
The image file or files to process.
.Parameter Offset
The time offset by which the EXIF DateTaken value should be adjusted.
Offset can be positive or negative and must be convertible to a [TimeSpan] type.
.Parameter PassThru
Switch parameter, if specified the paths of the image files processed are written to the pipeline.
The PathInfo objects are additionally decorated with the Old and New EXIF DateTaken values.
.Example
Update-ExifDateTaken img3.jpg -Offset 0:10:0 -WhatIf
Update the img3.jpg file, adding 10 minutes to the DateTaken property
.Example
Update-ExifDateTaken *3.jpg -Offset -0:01:30 -Passthru|ft path, exifdatetaken
Subtract 1 Minute 30 Seconds from the DateTaken value on all matching files in the current folder
.Example
gci *.jpeg,*.jpg|Update-ExifDateTaken -Offset 0:05:00
Update multiple files from the pipeline
.Example
gci *.jpg|Update-ExifDateTaken -Offset 0:5:0 -PassThru|Rename-Item -NewName {"Holday Snap {0:MM-dd HH.mm.ss}.jpg" -f $_.ExifDateTaken}
Updates the EXIF DateTaken on multiple files and renames the files based on the new time
.Outputs
If -PassThru is specified, the scripcmdlet outputs FileInfo objects with additional ExifDateTaken
and ExifOriginalDateTaken properties that can be used for later processing.
.Notes
This scriptcmdlet will overwrite files without warning - take backups first...
.Functionality
Modifies the EXIF DateTaken image property on a specified image file.
#>
V1.0 (Current Version) November 2015
Initial release to the PowerShell Gallery
V0.1-0.9
Dev versions
See all my other PS Gallery modules:
Find-Module | Where Author -like 'Chris*Warwick'