Skip to content

Instantly share code, notes, and snippets.

@johnrobertmcc
Last active March 11, 2022 20:32
Show Gist options
  • Save johnrobertmcc/fbb6d4e2cba7803eaf629013e1dfe84c to your computer and use it in GitHub Desktop.
Save johnrobertmcc/fbb6d4e2cba7803eaf629013e1dfe84c to your computer and use it in GitHub Desktop.
function ctwp() {
extension=$1 # take the extension you provided the function
for i in *.$extension # iterate through the files in the directory based on the extension
do
file=$i # declare the file as an easy-to-read variable
convert $file ${file%.*}.webp
# The above line:
#a) executes the ImageMagick command, and
#b) removes the basename from the file to grab only the file name
#(so ‘bull.jpg’ becomes ‘bull’)
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment