Skip to content

Instantly share code, notes, and snippets.

@oscarmcm
Last active January 28, 2023 02:08
Show Gist options
  • Save oscarmcm/8015985 to your computer and use it in GitHub Desktop.
Save oscarmcm/8015985 to your computer and use it in GitHub Desktop.
Script para aligerar fotos / reducir calidad y tamañoPara que el script funcione es necesario tener instalado gawk.
#!/bin/bash
# Programa en bash que cambia recursivamente la calidad de todos los ficheros
# .jpg a una calidad del 80%.
func_convertir()
{
for Fichero in *
do
(
if [ -d "$Fichero" ]; then
cd "$Fichero"
echo `pwd`
func_convertir
fi
)
if [ -f "$Fichero" ]
then
Extension=`echo $Fichero | gawk -F. '{print $2}'`
echo "Fichero es: $Fichero // Extension es: $Extension"
if [ $Extension = "jpg" ]; then
echo "`pwd`/$Fichero se va a optimizar..."
convert -quality 80% "$Fichero" "$Fichero"
fi
if [ $Extension = "JPG" ]; then
echo "`pwd`/$Fichero se va a optimizar..."
convert -quality 80% "$Fichero" "$Fichero"
fi
fi
done
}
func_convertir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment