Last active
October 10, 2020 07:25
-
-
Save feklee/1e395deafb33404372926e8db424fe91 to your computer and use it in GitHub Desktop.
Convert image files to PDF
This file contains 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 | |
# Some of the `getopts` code has been taken from: | |
# http://mywiki.wooledge.org/BashFAQ/035#getopts | |
# Felix E. Klee <[email protected]> | |
W=210 | |
H=297 | |
D=300 | |
# Usage info | |
show_help() { | |
cat << EOF | |
Usage: ${0##*/} [-hWHD] [IMAGE FILE]... | |
Convert image files to: out.pdf | |
-h display this help and exit | |
-W WIDTH width in mm, default $W | |
-H HEIGHT height in mm, default $H | |
-D DPI resolution, default $D | |
EOF | |
} | |
# Initialize our own variables: | |
output_file="" | |
OPTIND=1 | |
# Resetting OPTIND is necessary if getopts was used previously in the script. | |
# It is a good idea to make OPTIND local if you process options in a function. | |
while getopts hW:H:D: opt; do | |
case $opt in | |
h) | |
show_help | |
exit 0 | |
;; | |
W) W=$OPTARG | |
;; | |
H) H=$OPTARG | |
;; | |
D) D=$OPTARG | |
;; | |
*) | |
show_help >&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift "$((OPTIND-1))" # Discard the options and sentinel -- | |
if [ "$#" -eq 0 ]; then | |
show_help >&2 | |
exit 1 | |
fi | |
magick "$@" -density $D -page %[fx:$W/25.4*$D]x%[fx:$H/25.4*$D] -resize %[fx:page.width]x%[fx:page.height]! out.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment