Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Last active May 14, 2023 16:41
Show Gist options
  • Save SteveGilham/c916d7b360fae82bce4f36eaf22d5361 to your computer and use it in GitHub Desktop.
Save SteveGilham/c916d7b360fae82bce4f36eaf22d5361 to your computer and use it in GitHub Desktop.
Script to extract SD Webui prompt data from .png files
[System.IO.Directory]::GetFiles((Get-Location), "?????-*.png") |
Group-Object -Property {[System.DateTime]::Parse([System.IO.File]::GetCreationTime($_).ToShortDateString())} |
Sort-Object -Property {[System.DateTime]::Parse($_.Name)} | % {
$names = $_.Group | Sort-Object -Property {[System.IO.File]::GetCreationTime($_)}
[PSCustomObject]@{
Key = $_.Name
Value = $names
}
} | % {
Write-Output ($_.Key.Split())[0]
$_.Value | % {
" `"$([System.IO.Path]::GetFileName($_).Substring(0,5))`"" | Write-Output
$bytes = [System.IO.File]::ReadAllBytes($_)
$index = 8
$found = $false
while (($index -lt $bytes.Length) -and (-not $found)) {
# Write-Output "index = $index"
$field = ($bytes[$index+3], $bytes[$index+2], $bytes[$index+1], $bytes[$index])
$length = [System.BitConverter]::ToInt32($field, 0)
# Write-Output "length = $length"
$chunk = [System.Text.Encoding]::ASCII.GetString($bytes, $index+4, 4)
# Write-Output "chunk = $chunk"
if ($chunk.Equals("tEXt")) {
$found = $true
$body = [System.Text.Encoding]::ASCII.GetString($bytes, $index+19, $length - 11)
Write-Output $body
}
$index = ($index + 12 + $length)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment