Skip to content

Instantly share code, notes, and snippets.

@hewigovens
Created April 19, 2023 11:05
Show Gist options
  • Save hewigovens/3d1f9dac6181dcc4678cc474a52493b0 to your computer and use it in GitHub Desktop.
Save hewigovens/3d1f9dac6181dcc4678cc474a52493b0 to your computer and use it in GitHub Desktop.
Merge images into a PDF by ChatGPT
#!/bin/bash
# Check if the correct number of arguments were provided
if [ $# -eq 0 ]; then
echo "Usage: $0 image_directory file_extension compression_quality"
exit 1
fi
dir="$1"
ext="${2:-png}"
quality="${3:-100}"
# Navigate to the specified directory
cd "$dir"
# Compress the images
mogrify -quality "$quality" *."$ext"
# Combine the images into a PDF file with the same name as the directory
pdfname=$(basename "$dir").pdf
convert *."$ext" "$pdfname"
# Verify that the PDF file was created
if [ -f "$pdfname" ]; then
echo "PDF file created successfully."
open "$pdfname"
else
echo "Error: PDF file not created."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment