Skip to content

Instantly share code, notes, and snippets.

@dfl
Last active March 9, 2024 16:59
Show Gist options
  • Save dfl/020061c782ed469e83acf4a28ca38e28 to your computer and use it in GitHub Desktop.
Save dfl/020061c782ed469e83acf4a28ca38e28 to your computer and use it in GitHub Desktop.
bash script to get stable diffusion parameters from an image file
#!/bin/bash
filetype=$(file -b --mime-type "$1")
if [[ "$(uname)" == "Darwin" ]]; then # MacOS
# Check if ImageMagick is installed
if ! command -v identify >/dev/null 2>&1; then
echo "ImageMagick is not installed. Installing..."
brew install imagemagick
fi
# Check if Exiv2 is installed
if ! command -v exiv2 >/dev/null 2>&1; then
echo "Exiv2 is not installed. Installing..."
brew install exiv2
fi
fi
if [[ $filetype == "image/png" ]]; then
identify -verbose "$1" | grep -A2 "invoke\|param\|prompt" | grep -v 'png:IHDR' | sed -e 's/"//g' -e 's/^[[:space:]]*parameters: //'
elif [[ $filetype == "image/jpeg" ]]; then
exiv2 "$1" 2>/dev/null | ack 'Exif comment' | awk '{print substr($0, index($0, "Unicode") + 8)}'
else
echo "Unsupported file type: $filetype"
fi
@dfl
Copy link
Author

dfl commented Mar 9, 2024

requires imagemagick and exiv2 packages
for Mac: brew install imagemagick exiv2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment