Skip to content

Instantly share code, notes, and snippets.

@erickacevedor
Created February 25, 2026 16:50
Show Gist options
  • Select an option

  • Save erickacevedor/5be8c03c59a53b39a1f101cac3f221b3 to your computer and use it in GitHub Desktop.

Select an option

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%
#!/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