Created
July 14, 2026 15:30
-
-
Save renegarcia/af638cbf946c189fa0c34d69300c2d8e to your computer and use it in GitHub Desktop.
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 | |
| # Converts a list of images to pdf | |
| # | |
| # Usage: | |
| # images-to-pdf.sh <image1> <image2> ... <output file> | |
| # | |
| # 1. Validación: Verificar que se pasen al menos dos argumentos (una imagen y el output) | |
| if [ "$#" -lt 2 ]; then | |
| echo "Error: Argumentos insuficientes." | |
| echo "Uso: $0 <imagen1> [imagen2 ...] <archivo_salida.pdf>" | |
| exit 1 | |
| fi | |
| # 2. Separar el último argumento (output) de las imágenes de entrada | |
| # ${@: -1} toma el último elemento de la lista de argumentos | |
| output="${@: -1}" | |
| # ${@:1:$#-1} toma todos los argumentos desde el primero hasta el penúltimo | |
| inputs="${@:1:$#-1}" | |
| # 3. Ejecutar el comando de ImageMagick | |
| # Usamos "$@" expandido a través de la variable 'inputs' para soportar espacios en los nombres de archivo | |
| magick $inputs -resize "2000x2000>" -compress jpeg -quality 80 "$output" | |
| echo "PDF creado con éxito en: $output;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment