Last active
July 4, 2025 15:39
-
-
Save AbduEhab/957a47f7aeac9bf6dff3d038e8cd159e to your computer and use it in GitHub Desktop.
The script I use to collect scanned book pages into a pdf
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
#!/bin/bash | |
echo "Warning, this script is currently very memory heavy. Use with caution." | |
shopt -s nullglob nocaseglob | |
parent_dir="$(pwd)" | |
for dir in */; do | |
[ -d "$dir" ] || continue | |
# Collect and sort image files numerically | |
mapfile -t images < <(find "$dir" -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.bmp" -o -iname "*.gif" -o -iname "*.webp" \) | sort -V) | |
# Skip if no images found | |
if [ ${#images[@]} -eq 0 ]; then | |
echo "No images in $dir" | |
continue | |
fi | |
# Output file path | |
output_pdf="${parent_dir}/${dir%/}.pdf" | |
# Convert to PDF | |
magick "${images[@]}" "$output_pdf" | |
echo "Created PDF: $output_pdf" | |
done | |
shopt -u nullglob nocaseglob | |
echo "Convertion Complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment