Skip to content

Instantly share code, notes, and snippets.

@spagu
Created March 30, 2019 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spagu/85e77c5067e7784bd566047440de40ff to your computer and use it in GitHub Desktop.
Save spagu/85e77c5067e7784bd566047440de40ff to your computer and use it in GitHub Desktop.
Converts any image to webp
#!/usr/local/bin/bash
# 1. Install ImageMagic
# 2.Add “image/webp webp” to the file mime.types ( it should be there already )
#
# 3.Add to your main Nginx configuration.
# map $http_accept $webp_suffix {
# default "";
# "~*webp" ".webp";
# }
#
# 4. Add to your vhost
# location ~* ^/wp-content/.+\.(png|jpg|tiff)$ {
# add_header Vary Accept;
# try_files $uri$webp_suffix $uri =404;
# }
#
# Usage:
# ./any2webp.sh file.jpg
#
# Output: file.jpg.webp
convert -resize 510x340 -strip -interlace Plane -gaussian-blur 0.05 -quality 100% $1 $1.webp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment