Last active
November 22, 2015 00:01
-
-
Save ntrrgc/9c0b767a320877802861 to your computer and use it in GitHub Desktop.
Comprimir fotos
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
#!/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