AmazonPhotoから入手したデータと手元のバックアップデータを使って
再度、GooglePhotoに登録を開始しました。
ところが、iPhoneのスクリーンショットで領域カットして保存したPNGデータがおかしい。
日付関連の情報がなく、すべてAmazonPhotoからダウンロードした日付でGooglePhotoにアップされてしまいます。
iPhoneから直接吸い上げた過去のPNGデータは全く問題ないんだけどね…
なんらかの処理がAmazonPhotoで行われてるってことなのかな…
AmazonPhotoは一応、無劣化の設定なんだけどね…
そこでExifToolというものを使って、PNGデータに日付属性を付加する処理を作成。
PowerShellでのサンプル。
一応これで、なんとか復旧&GooglePhoto登録の目処が立ちました。
# 初期化
Remove-Item *_original.* -Force -ErrorAction SilentlyContinue# シンプル重複除去: FullNameでグループ化→最初の1つ
$files = Get-ChildItem *.png,*.jpg,*.jpeg,*.JPG,*.PNG -ErrorAction SilentlyContinue |
Sort-Object BaseName |
Group-Object FullName |
ForEach-Object { $_.Group[0] }$total = $files.Count
$success = 0
Write-Host "重複除去後: $total ファイル" -ForegroundColor Cyanforeach ($file in $files) {
$baseName = $file.BaseName
$fullPath = $file.FullName
# 安全抽出
if ($baseName.Length -lt 21) { continue }
$year = $baseName.Substring(0,4)
$month = $baseName.Substring(5,2)
$day = $baseName.Substring(8,2)
$hour = $baseName.Substring(12,2)
$min = $baseName.Substring(15,2)
$sec = $baseName.Substring(18,2)
if ([int]$month -ge 1 -and [int]$month -le 12 -and [int]$hour -lt 24 -and [int]$min -lt 60) {
$dtStr = "$year`:$month`:$day $hour`:$min`:$sec"
} else { continue }
# 進捗(簡易)
$percent = [math]::Round(($success / $total) * 100)
Write-Host "[$($success+1)/$total `($percent`%)`] $($file.Name)" -ForegroundColor Cyan -NoNewline
# exiftool最適
$args = @(
'-overwrite_original_in_place', '-P', '-m',
'-ignoreMinorErrors', '-ignoreMajorErrors', '-F',
"-EXIF:DateTimeOriginal=$dtStr",
"-FileModifyDate=$dtStr"
)
& exiftool.exe $args $fullPath > $null 2>&1
if ($LASTEXITCODE -le 1) {
Write-Host " " -ForegroundColor Green
$success++
} else {
Write-Host " " -ForegroundColor Red
}
}Write-Host "`n`n=== 全完了: $success / $total 成功 ===" -ForegroundColor Green
Remove-Item *_original.* -Force -ErrorAction Sile