Skip to content

Instantly share code, notes, and snippets.

@harmishhk
Created April 13, 2016 17:03
Show Gist options
  • Save harmishhk/a005f6e623ab3ff58709448803cd3da2 to your computer and use it in GitHub Desktop.
Save harmishhk/a005f6e623ab3ff58709448803cd3da2 to your computer and use it in GitHub Desktop.
powershell script to copy gps-metadata between image files
# script to copy GPS metadata between files based on names.
# implemented for photos from Lumia 1020 phone which stores images in two sizes,
# one of them (low resolution image) has GPS but the other (high resolution image) does not!
# requires ExifTool: http://www.sno.phy.queensu.ca/~phil/exiftool
# author: Harmish Khambhaita, v0.1, 13/04/2016
# specify directory to process photos
$rootFolder = "C:\Users\your_name\Pictures\lumia_1020"
# specify location for exiftool
$exifTool = "C:\Users\your_name\Downloads\exiftool-10.14\exiftool.exe"
# main script, no need to change anything below this line
# check if root folder exist
if (-not (Test-Path -Path $RootFolder)) { Write-Output "root folder does not exist"; break }
# get all files in the root folder
$fileEntries = [IO.Directory]::GetFiles($RootFolder)
$noHigresFiles = @()
$highresFiles = @()
$processedFiles = @()
$unprocessedFiles = @()
# process files one-by-one
foreach($fileName in $fileEntries)
{
# select high resolution images
if ($fileName.Contains("highres"))
{
$highresFiles = $highresFiles + $fileName
$lowResFileEntries = $fileEntries -like $fileName.Replace("__highres", "")
if ($lowResFileEntries.Length -ne 1)
{
[Console]::WriteLine("Found " + $lowResFileEntries.Length + " (!= 1) entries for " + $lowResFileEntries)
$unprocessedFiles = $unprocessedFiles + $fileName
return
}
$lowResFileName = $lowResFileEntries[0]
# we now have lowres and highres files
#[Console]::WriteLine("Found pair:`n`t" + $fileName + "`n`t" + $lowResFileName)
#$metaLow=([xml](.$ExiftoolFolder\exiftool.exe $lowResFileName -X -r)).rdf.description
#$metaHigh=([xml](.$ExiftoolFolder\exiftool.exe $fileName -X -r)).rdf.description
.$exifTool -tagsFromFile $lowResFileName -gps:all -overwrite_original $fileName
$processedFiles = $processedFiles + $fileName
}
else
{
$noHigresFiles = $noHigresFiles + $fileName
}
}
# printing out summary
[Console]::WriteLine("Processed " + $processedFiles.Length + " files`n" `
+ "`tout of " + $highresFiles.Length + " high-resolution image fiels`n" `
+ "`tand " + $unprocessedFiles.Length + " remained unprocessed`n" `
+ "`tthere were total " + $fileEntries.Length + " files and " + $noHigresFiles.Length + " non-high-resolution-image files`n" `
+ "`tin " + $rootFolder + " folder")
[Console]::WriteLine("`nProcessed files:")
foreach($file in $processedFiles)
{
[Console]::WriteLine("`t" + $file)
}
[Console]::WriteLine("`nUnprocessed files:")
foreach($file in $unprocessedFiles)
{
[Console]::WriteLine("`t" + $file)
}
[Console]::WriteLine("`nNon-high-resolution-image files:")
foreach($file in $noHigresFiles)
{
[Console]::WriteLine("`t" + $file)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment