Created
January 2, 2026 00:14
-
-
Save NoRaincheck/1e7ab00d2cfbfbe8d62b238b084dcaf0 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
| #!/bin/bash | |
| PATH=/usr/local/bin:/opt/homebrew/bin/:$PATH | |
| # Check if an argument is provided | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <input-image-file>" | |
| exit 1 | |
| fi | |
| # Define input and output files | |
| input_file="$1" | |
| output_file="${input_file%.*}.out.pdf" | |
| temp_file="/tmp/convert_pdf/temp.jpg" | |
| # create temporary directory if it doesn't exist | |
| mkdir -p /tmp/convert_pdf | |
| # Convert the image to a temporary file with a specified density | |
| magick -density 300 "$input_file" "$temp_file" | |
| # Check if the conversion to temporary file was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error converting $input_file to $temp_file" | |
| exit 1 | |
| fi | |
| # combine all the jpg pages into a single pdf | |
| magick /tmp/convert_pdf/temp*.jpg "$output_file" | |
| # Check if the PDF conversion was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error converting $temp_file to $output_file" | |
| exit 1 | |
| fi | |
| # Remove the temporary file | |
| rm -r -f /tmp/convert_pdf | |
| # Success message | |
| echo "Successfully converted $input_file to $output_file" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment