Created
July 7, 2024 08:36
-
-
Save WillBishop/b2ef8619006ef1a704a149efc42d3283 to your computer and use it in GitHub Desktop.
Convert all images from png/jpeg to heif
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
# Convert .png and .jpeg files to .heif format, ensuring "xcassets" is in the path | |
# Depending on what folder your icons are in, you may wish to append ' -not -path "*/Icons/*"' to that find command so you don't convert all your icon assets. | |
find . -path "*xcassets*" \( -name "*.png" -o -name "*.jpeg" \) | while read -r file; do | |
# Get the filename without the extension | |
filename="${file%.*}" | |
# Run the magick command to convert the file to .heif | |
/opt/homebrew/bin/magick "$file" "$filename.heif" | |
rm "$file" | |
# Print a message indicating the conversion | |
echo "Converted $file to $filename.heif" | |
done | |
# Replace "png" and "jpeg" with "heif" in .json files, ensuring "xcassets" is in the path and excluding "*/Icons/*" | |
# Same warning as above! | |
find . -path "*xcassets*" -name "*.json" | while read -r file; do | |
# Check if the file contains "png" or "jpeg" | |
if grep -qE "png|jpeg" "$file"; then | |
# Use sed to find and replace "png" and "jpeg" with "heif" in the file | |
sed -i '' 's/png/heif/g; s/jpeg/heif/g' "$file" | |
# Print a message indicating the replacement | |
echo "Replaced 'png' and 'jpeg' with 'heif' in $file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment