Created
February 25, 2026 16:50
-
-
Save erickacevedor/5be8c03c59a53b39a1f101cac3f221b3 to your computer and use it in GitHub Desktop.
Convierte imágenes a JPG (máx 1300px ancho) y genera versión WebP al 70%
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # batch-resize-jpg-webp.sh | |
| # Convierte imágenes a JPG (máx 1300px ancho) y genera versión WebP al 70% | |
| OUTDIR="${OUTDIR:-output}" | |
| MAX_W="${MAX_W:-1300}" | |
| WEBP_Q="${WEBP_Q:-70}" | |
| JPG_Q="${JPG_Q:-82}" | |
| mkdir -p "$OUTDIR/jpg" "$OUTDIR/webp" | |
| shopt -s nullglob nocaseglob | |
| FILES=( *.jpg *.jpeg *.png *.tif *.tiff *.heic *.webp ) | |
| if [ ${#FILES[@]} -eq 0 ]; then | |
| echo "No se encontraron imágenes en $(pwd)" | |
| exit 1 | |
| fi | |
| for f in "${FILES[@]}"; do | |
| base="$(basename "$f")" | |
| name="${base%.*}" | |
| magick "$f" \ | |
| -auto-orient \ | |
| -strip \ | |
| -resize "${MAX_W}x>" \ | |
| -quality "$JPG_Q" \ | |
| "$OUTDIR/jpg/${name}.jpg" | |
| cwebp -q "$WEBP_Q" \ | |
| "$OUTDIR/jpg/${name}.jpg" \ | |
| -o "$OUTDIR/webp/${name}.webp" \ | |
| >/dev/null | |
| echo "Procesado: $f" | |
| done | |
| echo "Listo. Archivos en $OUTDIR/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment