Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Powershell functions to read and modify the "Date Picture Taken" EXIF tag on jpeg images.
- [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- # Define function to return "Date Picture Taken" EXIF Tag value
- function get-datetaken {
- param ($path)
- $bmp = new-object System.Drawing.Bitmap $path
- $prop = $bmp.GetPropertyItem(36867)
- $date = [System.Text.Encoding]::UTF8.GetString($prop.Value)
- [DateTime]::Parse($date.Substring(0,4)+"/"+$date.Substring(5,2)+"/"+$date.Substring(8))
- $bmp.Dispose()
- }
- # Define function to set "Date Picture Taken" EXIF Tag value
- function set-datetaken {
- param ([string]$inputPath, [string]$outputPath, [DateTime]$date)
- $dateBytes = [System.Text.Encoding]::UTF8.GetBytes($date.ToString("yyyy:MM:dd HH:mm:ss")) + 0
- $bmp = new-object System.Drawing.Bitmap $inputPath
- $prop = $bmp.GetPropertyItem(36867)
- $prop.Value = $dateBytes
- $bmp.SetPropertyItem($prop)
- $bmp.Save($outputPath)
- $bmp.Dispose()
- }
- # Define function to increment "Date Picture Taken" EXIF Tag values by specified TimeSpan
- function adjust-datetaken {
- param ([string]$inputPattern, [string]$outputDirectory, [TimeSpan]$span)
- gci $inputPattern | foreach { `
- $out = [IO.Path]::Combine($outputDirectory, $_.Name); `
- set-datetaken $_.FullName $out (get-datetaken $_.FullName).Add($span); `
- write-output "$($out): $(get-datetaken $out)" `
- }
- }
- # get-datetaken "c:\temp\exif\test.jpg"
- # set-datetaken "c:\temp\exif\test.jpg" "c:\temp\exif\test-output.jpg" ([DateTime]::Parse("2009/08/05 7:06 PM"))
- # $span = [DateTime]::Parse("2010/7/19 10:51AM") - [DateTime]::Parse("2004/12/29 11:37 PM")
- # adjust-datetaken "d:\home\photos\2010 Road Trip\DSC*.jpg" "C:\Temp\EXIF" $span
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement