-
-
Save thorade/5970020 to your computer and use it in GitHub Desktop.
# Declare functions first | |
# this function reads the "date taken" from extended properties | |
function Get-DateTaken { | |
Param( | |
[string]$filePath | |
) | |
$shell = New-Object -COMObject Shell.Application | |
$folder = Split-Path $filePath | |
$file = Split-Path $filePath -Leaf | |
$shellfolder = $shell.Namespace($folder) | |
$shellfile = $shellfolder.ParseName($file) | |
$takenDateID = 12 | |
$takenDate = $shellfolder.GetDetailsOf($shellfile, $takenDateID) | |
$asci = [System.Text.Encoding]::ASCII | |
$asciDate = $asci.GetString($asci.GetBytes($takenDate)) | |
$date= $asciDate -replace '\?' | |
$date = [DateTime]::Parse($date); | |
return $date | |
} | |
# get current directy | |
$curDir = Split-Path -Parent $MyInvocation.MyCommand.Path | |
# Autorotate and optimize using IrfanView | |
# Set File CreationDate to Exif Date | |
# Warning: this may change the Hash of the file | |
$argList = "$curDir\*.jpg /jpg_rotate=(6,1,1,0,1,300,0,0)" | |
Start-Process -Wait -FilePath "${env:ProgramFiles}\IrfanView\i_view32.exe" -ArgumentList $argList | |
# get a list of jpg files | |
$jpgFiles = Get-ChildItem $curDir\*.jpg | sort-object -property CreationTime | |
# Rename jpg files to Date_Time_Hash.jpg | |
ForEach ($pic In $jpgFiles){ | |
$HashString = ((Get-FileHash $pic -Algorithm SHA256).Hash).Remove(4) | |
$NeuerName = (Get-DateTaken($pic)).toString("yyyyMMdd_HHmmss") + "_" + $HashString + ".jpg" | |
Rename-Item $pic -NewName $NeuerName | |
} |
@kiquenet sorry for answering late, it seems that comments on gists do not trigger an email notification.
Does the @mention make sure you get an email?
Regarding your question: This script should be very easy to adapt to make it work with IrfanView Portable.
So far, I have not used ImageMagick, so I can't help with that.
There are also some Python libraries that can read EXIF data.
Use Hash instead of random, to get reproducible results:
http://stackoverflow.com/q/26930090/874701
Get-FileHash -Algorithm SHA256
If no value is specified, or if the parameter is omitted, the default value is SHA256
https://technet.microsoft.com/de-de/library/dn520872.aspx
If IrfanView has not been run, the CreationDate is wrong.
In this case, the function Get-DateTaken is more reliable.
Inspired by: http://www.zold.org/zold/ps_archive_images_takendate/
http://stackoverflow.com/q/9552367/874701
The script as it is will only work from ISE, see
http://stackoverflow.com/a/6040725/874701
Any scripts using ImageMagick for image processing ?
Or portable IrfanView ?