aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2019-01-14 15:48:33 +0800
committerAaron LI <aly@aaronly.me>2019-01-14 15:48:33 +0800
commitdffc52e630dc884a9702351d8e986779e1d4915f (patch)
treebee308be20a3ab7c9e7ca16df5276dc7db9a5612
parent591603fcdb0660ec6689019e39437c2d9e513229 (diff)
downloadatoolbox-dffc52e630dc884a9702351d8e986779e1d4915f.tar.bz2
cli/jpg2pdf.sh: Rewrite to read PS commands from file
Otherwise it is very easy to come across the error of "command line too long" ...
-rwxr-xr-xcli/jpg2pdf.sh45
1 files changed, 22 insertions, 23 deletions
diff --git a/cli/jpg2pdf.sh b/cli/jpg2pdf.sh
index 9041009..ccdd4d7 100755
--- a/cli/jpg2pdf.sh
+++ b/cli/jpg2pdf.sh
@@ -1,42 +1,41 @@
#!/bin/sh
#
-#############################################################################
+# Copyright (c) 2019 Aaron LI <aly@aaronly.me>
+# MIT License
#
-# Shellscript to convert a set of JPEG files to a multipage PDF.
+# Convert a set of JPEG files to a multipage PDF using Ghostscript and
+# ImageMagick (requires the "identify" command).
#
-# Requirements: (1) Ghostscript needs to be installed on the local system.
-# (2) ImageMagick needs to be installed on the local system.
+# Credit: pipitas@gmail.com
#
-# Usage: jpegs2pdf.sh output.pdf file1.jpeg [file2.jpeg [file2.jpeg [...]]]
-#
-# Copyright (c) 2007, <pipitas@gmail.com>
-# Use, distribute and modify without any restrictions.
-#
-# Versions:
-# v1.0.0, Jul 12 2007: initial version
-# v1.0.1, Jan 07 2011: set viewJPEG.ps path (self-compiled GS 9.02)
-#
-#############################################################################
if [ $# -lt 2 ]; then
- echo "Usage:"
- echo " `basename $0` output.pdf 1.jpg ..."
+ echo "usage: ${0##*/} output.pdf 1.jpg ..."
exit 1
fi
-outfile=$1
+outfile="$1"
shift
-param=""
-for i in "$@" ; do
- dimension=$(identify -format "%[fx:(w)] %[fx:(h)]" "${i}")
- param="${param} <</PageSize [${dimension}]>> setpagedevice (${i}) viewJPEG showpage"
+fcmd=$(mktemp)
+N=$#
+i=0
+echo "Total images: ${N}"
+while [ -n "$1" ]; do
+ f="$1"; shift; i=$((${i} + 1))
+ echo -n "${i}.."
+ dim=$(identify -format "%[fx:(w)] %[fx:(h)]" "${f}")
+ echo "<</PageSize [${dim}]>> setpagedevice (${f}) viewJPEG showpage" \
+ >> ${fcmd}
done
gs \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
- -o "$outfile" \
+ -o "${outfile}" \
viewjpeg.ps \
- -c "${param}"
+ -f ${fcmd}
+
+rm -f ${fcmd}
+echo "Output file: ${outfile}"