Skip to content

Instantly share code, notes, and snippets.

@theonelucas
Created May 4, 2020 15:28
Show Gist options
  • Save theonelucas/dcd80a082abd569a7b64c5f14824a545 to your computer and use it in GitHub Desktop.
Save theonelucas/dcd80a082abd569a7b64c5f14824a545 to your computer and use it in GitHub Desktop.
#!/bin/bash
images=()
# Get all non JPG images
readarray -d '' images < <(find ./ -type f \( -iname \*.jpeg -o -iname \*.png \) -print0)
# Convert them to JPG
for i in "${!images[@]}"
do
image_path=${images[i]}
image_name="${image_path%.*}"
convert "$image_path" -verbose -quality 100% "${image_name}.jpg"
rm "$image_path"
done
# Optimize all images
find -type f -name "*.jpg" -exec jpegoptim -ps --strip-all {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment