Last active
January 15, 2025 20:11
-
-
Save SteveGilham/a92ee63c4c37b1ad333dd262d7081256 to your computer and use it in GitHub Desktop.
Using exiftool to add the prompt to a Bing Image Creator download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Using exiftool (see https://exiftool.org/) to add the prompt to a Bing Image Creator download. | |
.DESCRIPTION | |
Use like | |
& '.\OneDrive\Pictures\aigen\prompt.ps1' "minimalist style corporate flower logo. simple, clean, uncluttered, modern, elegant" | |
or | |
& '.\OneDrive\Pictures\aigen\prompt.ps1' -prompt "minimalist style corporate flower logo. simple, clean, uncluttered, modern, elegant" | |
to add the prompt | |
.NOTES | |
File Name : Prompt.ps1 | |
Requires : PowerShell Version 2.0 | |
.PARAMETER Prompt | |
The string you passed to Bing, quoted and, as needs be, escaped e.g. for quotation marks | |
Hard codes - assumes files downloaded to the default download directory, | |
and a location under the OneDrive Pictures folder called "aigen" | |
Exiftool lives in a folder "exif" under the OneDrive Documents folder | |
Adjust these to taste | |
Extract all prompts in the current folder by (again with suitably adjusted paths) | |
& "$($env:OneDrive)\documents\exif\exiftool.exe" -ext+ jfif -s -Artist "$($env:OneDrive)\Pictures\aigen" > "$($env:OneDrive)\documents\aigen.txt" | |
#> | |
param([String]$prompt="") | |
try { | |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
} | |
catch { | |
# The first time in ISE we get an "invalid handle". Write something with -VER and try again. | |
exiftool -VER | |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
} | |
#escape non-ASCII characters | |
$builder = new-object "system.text.stringbuilder" | |
$prompt.ToCharArray() | % { | |
if ([Char]::isAscii($_)) { $builder = $builder.Append($_) } | |
else { $encoded = "\u" + ([int]$_).ToString( "x4" ) | |
$builder = $builder.Append($encoded) } | |
} | |
$prompt1 = $builder.ToString() | |
# Set Working directory. | |
$save = Get-location | |
Set-Location "$($env:OneDrive)\Pictures\aigen" # or wherever you're archiving to | |
dir "$($env:USERPROFILE)\downloads\_*.j*" | % { # the downloads are of the form `underscore followed by a guid`.jpg or .jfif | |
$newname = "bing$($_.CreationTime.ToUniversalTime().ToString("yyMMdd-HHmmss_ffff")).jpg" | |
mv $_ "$($env:OneDrive)\Pictures\aigen\$($newname)" # or wherever you're archiving to | |
& "$($env:OneDrive)\Documents\exif\exiftool.exe" -echo4 `{ready18`} -CHARSET FILENAME=UTF8 -CHARSET UTF8 -v0 -overwrite_original -sep * -c %.6f° -API WindowsWideFile=1 "-exif:artist=$($prompt1)" $newname -execute18 2>&1 | %{"$_"} | |
} | |
Set-Location $save | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment