Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Frankenmint/3fbf186fcb8fa8ed003b9b36c5f55788 to your computer and use it in GitHub Desktop.
Save Frankenmint/3fbf186fcb8fa8ed003b9b36c5f55788 to your computer and use it in GitHub Desktop.
webPng.sh
#!/bin/bash
# ARE YOU SICK OF THE INTERNET BEING STUPID WITH GIVING YOU WEBP FILES?
# Like you made EVERYTHING to work with pngs and (ugh) jpegs. Cool, I get it save
# money, use compression standard wepb. FUCK YOU... update the tooling on the other side of the coin then!!!
# OK so download this and save it as a shell file (then give it executable permissions)
# so.. sudo chmod +x webPng.sh (or whatever you named it). Now, run it in the terminal in the same
# folder where you downloaded those pesky webP files and PRESTO it will convert them into PNG files, YAAY :)
# I maed this with the help of chatgpt, fyi
# Ensure imagemagick is installed
if ! command -v convert &> /dev/null
then
echo "imagemagick could not be found, please install it using 'sudo apt-get install imagemagick'"
exit
fi
# Function to convert file to PNG and delete the original
convert_and_delete() {
local file=$1
local extension=$2
echo "Converting $file to ${file%.$extension}.png and then deleting the original $extension file..."
convert "$file" "${file%.$extension}.png"
if [ $? -eq 0 ]; then
rm "$file"
else
echo "Conversion failed for $file, not deleting."
fi
}
# Convert all .webp and .avif files to .png, then delete the original files
for file in *.{webp,avif}; do
if [[ $file == *.webp ]]; then
convert_and_delete "$file" "webp"
elif [[ $file == *.avif ]]; then
convert_and_delete "$file" "avif"
fi
done
echo "Conversion and deletion completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment