Skip to content

Instantly share code, notes, and snippets.

@ntrrgc
Last active November 22, 2015 00:01
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 ntrrgc/9c0b767a320877802861 to your computer and use it in GitHub Desktop.
Save ntrrgc/9c0b767a320877802861 to your computer and use it in GitHub Desktop.
Comprimir fotos
#!/bin/bash
if [ ! $# -eq 2 ]; then
echo "Este es un script para comprimir fotos."
echo "Uso: $1 <carpeta con fotos originales> <carpeta de destino para las fotos comprimidas>"
fi
if ! which convert > /dev/null 2>&1; then
echo "No tienes imagemagick... Procedo a instalarlo."
sudo bash -c 'apt-get update && apt-get -y install imagemagick'
fi
max_resolution="1920x1080"
count=0
for image in "$1"/*; do
if [[
"${image,,}" == *.png ||
"${image,,}" == *.jpg ||
"${image,,}" == *.jpeg
]]; then
filename="$(basename "$image")"
convert "$image" -scale ">$max_resolution" "$2/$filename"
((count++))
fi
done
if [ $count -gt 0 ]; then
echo "Se han convertido $count imágenes."
else
echo "No se han encontrado imágenes que convertir en la carpeta de fotos originales."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment