Last active
March 9, 2024 16:59
-
-
Save dfl/020061c782ed469e83acf4a28ca38e28 to your computer and use it in GitHub Desktop.
bash script to get stable diffusion parameters from an image file
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires imagemagick and exiv2 packages
for Mac:
brew install imagemagick exiv2