Michael Meissner <> wrote:
>Ignoramus18262 <> writes:
>
>> I would like to print photos, four on each page. That is, each page
>> would have four photos that I could cut with scissors into four
>> individual photos. Is there some linux proggy or a script that could
>> do it. Thanks
>
>The montage program that is in the ImageMagick suite of tools will do this
>using the -tile and -geometry options:
ImageMagick tools can do it a number of ways. There is
indeed "montage". There is also "composite". And in
fact the way that I've done it is with "convert" using
the "+append" argument.
I'm a little hesitant to post this script, because it has
been used very little and is probably full of no end of
bugs that will reformat your hard drive... but it does
put 4 images on one page for printing.
#!/bin/bash
#
# Composite 4 images for printing
#
prog=$(basename ${0})
function usage () {
echo -e \
"${prog} ${b}[${n}-h | -? | --help${b}]${n} \\"
echo -e \
" ${b}[${n}-i NNxNN -c NNxNN -s nn -v nn -o ${i}outfile${n}${b}]${n} \\"
echo -e \
" ${i}image_file1${n} ${b}[${n} ... ${n}${i}image_file4${n} ${b}]${n}"
echo -e "\
${b}${prog}${n} generates a single image output
file, ${i}${out}${n}, made up of 4 images from images
files specified on the command line. If the command
line specifies only 1 image file the output will be a
times 4 composite of that one image. If two image
files are specified, they will be the left pair and
right pair respectively. If three image files are
specified the first two will be on top and the third
will be duplicated as the composite's two bottom
images."
echo ""
echo -e "\
${b}OPTIONS${n}"
echo -e "\
-c NNxNN -- Sets the white border around the
composite output image to NNxNN."
echo -e "
-i NNxNN -- Sets the white border around each
individual image to NNxNN."
echo -e "
-v n -- Enables more progress messages when
n > 2 and fewer if n < 2."
echo -e "
-s nn -- Scales images in the composite smaller
the divisor nn. Default is 4, which
makes the output image about the size
of the largest original individual
image. -s 1 is another useful value."
echo ""
}
# **** DEFAULT CONFIGURATION ****
#
# The generated composite output file is named ${out}.
# The extent determines the format. Note that other
# "convert" attributes can be set with the variable.
# The -o option also sets the output file name.
# out="out.jpg" is an example.
out="out.jpg"
#
# The image files will be scaled by ${scale} amount. If the
# output should be the same size as the largest input image,
# set this to 4. If the output image should just be as
# big as all 4 images combined, set this to 1. The -s option
# also sets this variable.
# scale=4 is an example.
scale=4
#
# The composite will have a border per ${cborder}.
# The -c option will also set this border.
# cborder="5x25" is an example.
cborder="5x25"
#
# The 4 images will have a border per ${iborder}.
# The -i option will also set this border.
# iborder="5x5" is an example.
iborder="5x5"
#
# The amount of information generated as the script
# progresses is adjusted with the -v option. The
# default is set with $verbose
# verbose=2 is an example.
verbose=2
#
# These define various ANSI X.64 terminal attributes that
# can be selected for $b or $i in the help screen.
#
nrm="\033[0m"
red="\033[31m"
grn="\033[32m"
yel="\033[33m"
blu="\033[34m"
mag="\033[35m"
cyn="\033[36m"
wht="\033[37m"
bld="\033[1m"
uln="\033[4m"
inv="\033[7m"
# If the help screen has chicken scratch instead of bold
# comment out these two:
b=${bld}
i=${uln}
n=${nrm}
# **** END OF CONFIGURATION ****
function cleanup () {
rm -f atmp.ppm btmp.ppm ctmp.ppm hi.ppm lo.ppm
if [ ${verbose} -gt 2 ] ; then
echo -e "${red}Merry ${grn}Christmas${n}...

"
fi
}
while [ ${#} -gt 0 ] ; do
if [ "${1:0:1}" == "-" ] ; then
option="${1:1}"
case "${1:1}" in
[?h]) usage; exit 0;;
help) usage; exit 0;;
-[?h]) usage; exit 0;;
-help) usage; exit 0;;
v) case "${2:0:1}" in
[0-9]) verbose=${2}; shift; shift; continue;;
esac;;
s) case "${2:0:1}" in
[0-9]) scale=${2}; shift; shift; continue;;
esac;;
c) case "${2:0:1}" in
[0-9]) cborder=${2}; shift; shift; continue;;
esac;;
i) case "${2:0:1}" in
[0-9]) iborder=${2}; shift; shift; continue;;
esac;;
o) out="${2}"; shift; shift; continue;;
*) break;;
esac
else
break
fi
shift
done
trap cleanup 0
number=${#}
case "${number}" in
0) echo -e "You ${red}must${nrm} specify from 1 to 4 image files."; exit 1;;
1) args=(${1} ${1} ${1} ${1});;
2) args=(${1} ${2} ${1} ${2});;
3) args=(${1} ${2} ${3} ${3});;
*) args=(${1} ${2} ${3} ${4});;
esac
j=0
width=0
height=0
for x in 0 1 2 3 ; do
set $(exiftool "${args[${x}]}" 2>&1)
if [ "${1}" != "ExifTool" ] ; then
echo -e "File ${i}${args[${x}]}${n} does not have a valid image format."
exit 1
fi
set $(exiftool "${args[${x}]}" | grep "Image Width")
neww=$(expr ${4} \/ ${scale})
set $(exiftool "${args[${x}]}" | grep "Image Height")
newh=$(expr ${4} \/ ${scale})
if [ ${newh} -lt ${neww} ] ; then
rotate[${x}]="-rotate 90"
if [ ${height} -lt ${neww} ] ; then height=${neww} ; fi
if [ ${width} -lt ${newh} ] ; then width=${newh} ; fi
else
if [ ${height} -lt ${newh} ] ; then height=${newh} ; fi
if [ ${width} -lt ${neww} ] ; then width=${neww} ; fi
fi
done
for x in 0 1 2 3 ; do
if [ ${width} -gt ${height} ] ; then
size[${x}]="size ${width}x${width}"
else
size[${x}]="size ${height}x${height}"
fi
done
if [ ${verbose} -gt 2 ] ; then
echo "verbose: ${verbose}"
echo "scale: ${scale}"
echo "iborder: ${iborder}"
echo "cborder: ${cborder}"
echo "out file: ${out}"
echo "height: ${height}"
echo "width: ${width}"
fi
if [ ${verbose} -gt 1 ] ; then
echo -e "Making ${size[0]} temp file from ${i}${args[0]}${n}"
fi
convert -re${size} ${args[0]} -bordercolor white \
-border ${iborder} ${rotate[0]} -${size[0]} -depth 16 atmp.ppm
top=("atmp.ppm" "atmp.ppm")
dt="Making double image file from ${i}${args[0]}${n} and ${i}${args[0]}${n}"
comp=("hi.ppm" "hi.ppm");
if [ ${number} -gt 1 ] ; then
if [ ${verbose} -gt 1 ] ; then
echo -e "making ${size[1]} temp file from ${i}${args[1]}${n}"
fi
convert -re${size} ${args[1]} -bordercolor white \
-border ${iborder} ${rotate[1]} -${size[1]} -depth 16 btmp.ppm
top=("atmp.ppm" "btmp.ppm")
dt="Making double image file from ${i}${args[0]}${n} and ${i}${args[1]}${n}"
fi
if [ ${number} -gt 2 ] ; then
if [ ${verbose} -gt 1 ] ; then
echo -e "making ${size[2]} temp file from ${i}${args[2]}${n}"
fi
convert -re${size} ${args[2]} -bordercolor white \
-border ${iborder} ${rotate[2]} -${size[2]} -depth 16 ctmp.ppm
top=("atmp.ppm" "btmp.ppm")
bot=("ctmp.ppm" "ctmp.ppm")
dt="Making double image file from ${i}${args[0]}${n} and ${i}${args[1]}${n}"
db="Making double image file from ${i}${args[2]}${n} and ${i}${args[2]}${n}"
comp=("hi.ppm" "lo.ppm");
fi
if [ ${number} -gt 3 ] ; then
if [ ${verbose} -gt 1 ] ; then
echo -e "making ${size[3]} temp file from ${i}${args[3]}${n}"
fi
convert -re${size} ${args[3]} -bordercolor white \
-border ${iborder} ${rotate[3]} -${size[3]} -depth 16 dtmp.ppm
bot=("ctmp.ppm" "dtmp.ppm")
db="Making double image file from ${i}${args[2]}${n} and ${i}${args[3]}${n}"
fi
if [ ${verbose} -gt 1 ] ; then
echo -e "${dt}"
fi
convert ${top[0]} ${top[1]} +append -depth 16 hi.ppm
if [ ${number} -gt 2 ] ; then
if [ ${verbose} -gt 1 ] ; then
echo -e "${db}"
fi
convert ${bot[0]} ${bot[1]} +append -depth 16 lo.ppm
fi
if [ ${verbose} -gt 1 ] ; then
echo -e "Making composite file ${i}${out}${n}"
fi
convert ${comp[0]} ${comp[1]} -append\
-bordercolor white -border ${cborder} \
-depth 16 -quality 100 ${out}
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)