-
-
Save cjimmy/e9849073cf65e9cf3ce8252f4dc27494 to your computer and use it in GitHub Desktop.
source ~/.bash_profile | |
# assumes you have cwebp installed | |
# https://developers.google.com/speed/webp/download | |
# Typing `cwebp` into terminal should result in anything but Command not found. | |
# Gist by Jimmy Chion | |
# shell script intended to be used in Mac Automator, | |
# so you can right-click on a file and convert the file(s) to webp | |
# In Automator, create a new `Service`, | |
# drag and drop a `Run Shell Script` and copy paste this gist | |
# Set top settings to `Service receives selected [image files] in [Finder.app]` | |
# Shell: [/bin/bash] (You can type `echo $SHELL` in Terminal to see what shell you're running) | |
# Pass input [as arguments] | |
# Save as... "Convert to Webp" (or whatever you want it to be called in your right-click menu) | |
for FILE in "$@" | |
do | |
echo "coverting file: $FILE" | |
EXT=${FILE##*.} # file extension | |
QUALITY=85 # quality for the image | |
# convert the image using cwebp and output a file with the extension replaced as .webp | |
cwebp -q $QUALITY "$FILE" -o "${FILE/%.$EXT/.webp}" &>/dev/null | |
done |
Hi thank you for your work :
I am doing it like that but, when i run the script i have no the exit file (and no message ...)
I'm on macos big and my terminal open on szh ... :-s
i have created an empty .bash_profile
thank you kindly !
ps : this command work properly on terminal :
loukas@Air ~ % cwebp -q 80 /Users/loukas/Downloads/20140629_172650.JPG -o /Users/loukas/Downloads/20140629_172650.webp
It works! Thank you for the script.
But whit two changes.
My shell use zsh, so i changed the first line in #! /bin/zsh and Shell: /bin/zsh.
Could don't not find cwebp, so I searched for the correct path, entered it instead of cwebp.
#! /bin/zsh
for FILE in "$@"
do
echo "coverting file: $FILE"
EXT=${FILE##*.} # file extension
QUALITY=100 # quality for the image
# convert the image using cwebp and output a file with the extension replaced as .webp
/usr/local/bin/cwebp -q $QUALITY "$FILE" -o "${FILE/%.$EXT/.webp}" &>/dev/null
done
Now it works correctly.
Whit QUALITY=100, the quality of the image in WebP is very good, and the compression is better then online compressor or app like Webp Converter.
It works! Thank you for the script cjimmy and sentimatteo
But with two changes.
Could don't not find cwebp, so I searched for the correct path, entered it instead of cwebp.
for FILE in "$@"
do
echo "coverting file: $FILE"
EXT=${FILE##*.} # file extension
QUALITY=100 # quality for the image
# convert the image using cwebp and output a file with the extension replaced as .webp
/usr/local/bin/cwebp -q $QUALITY "$FILE" -o "${FILE/%.$EXT/.webp}" &>/dev/null
done
Hello Jimmy,
Thanks for sharing this gist. I added an update to the script that makes it possible to add automator actions after the "Run shell script".