Created
September 14, 2020 08:01
-
-
Save le-martre/ae3280f62981dba7228f474b5f83f73c to your computer and use it in GitHub Desktop.
Bash command to resize an image in multiple sizes at once for usage in websites (img srcset tags)
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
# You need imagemagick to have the "convert" command available | |
# Debian based distros => sudo apt-get install imagemagick | |
# Example command usage : | |
# $ web_resize coffee.jpg 320 1024 1980 | |
# Will create : | |
# - coffee-320.jpg | |
# - coffee-1024.jpg | |
# - coffee-1980.jpg | |
function web_resize() { | |
name="${1%%.*}" | |
extension="${1#*.}" | |
for arg in "${@:2}"; do | |
convert $1 -resize "${arg}x${arg}" "${name}-${arg}.${extension}" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment