Last active
July 1, 2024 14:39
-
-
Save drygdryg/eb75fec65f63a98e2bfaec06e12c0034 to your computer and use it in GitHub Desktop.
Find and optimize all PNG and JPG files in a directory using oxipng & jpegoptim
This file contains 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 | |
directory=$1 | |
pngfile_list=$(mktemp /tmp/oxipng_to_proceed.XXXXXX) | |
jpegfile_list=$(mktemp /tmp/jpegoptim_to_proceed.XXXXXX) | |
find "$directory" -maxdepth 1 -type f -exec file --mime-type {} + | grep 'image/png$' | cut -d ':' -f 1 > $pngfile_list | |
find "$directory" -maxdepth 1 -type f -exec file --mime-type {} + | grep 'image/jpeg$' | cut -d ':' -f 1 > $jpegfile_list | |
xargs --arg-file=$pngfile_list -d '\n' oxipng | |
xargs --arg-file=$jpegfile_list -d '\n' jpegoptim -m 80 -w `nproc --all` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment