Skip to content

Instantly share code, notes, and snippets.

@le-martre
Created September 14, 2020 08:01
Show Gist options
  • Save le-martre/ae3280f62981dba7228f474b5f83f73c to your computer and use it in GitHub Desktop.
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)
# 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