@anthony: I made small customization to your suggestion, and it centers my images fantastically well on the canvas thanks:
#convert test1.png -monochrome -alpha set -background white -gravity center -extent 4800x6300 -flatten centered.png
My scanned document appears perfectly centered on a white background of size 4800x6300 aka 8.5x11
Some notes:
1) I would love to see this technique "centering an image onto a canvas" posted to your website:
http://www.imagemagick.org/Usage/canvas/
#convert test1.png -monochrome -alpha set -background white -gravity center -extent 4800x6300 -flatten centered.png
2) Also for your website, the concept of creating a "virtual canvas" as follows:
#convert -page 9900x6300 -background white -flatten $i $i
Of course you probably wouldn't want to show "-flatten" on the website.
Thanks kindly for your help
P.S. In case you are interested: the following script is what I use to make very compact PDF manuals out of monochrome images. It compresses each image into both Deflate and Group4. Then it picks the smallest of the two, and strings them all to a pdf. Note that the script is about 6 times as long as it needs to be and uses tools other than just imagemagick, because i decided use a buggy old version of imagemagick, but it's all in the comments. No response necessary because this is just for your entertainment.
Before running the script, I pre-process my images to center them as per your advice:
for i in *.[PpBb][NnMm][GgPp]; do echo $i; convert -monochrome -alpha set -background white -gravity center -extent 4800x6300 -flatten $i $i; done
#!/bin/bash
# chmod 744 makemanual.sh
# ./makemanual.sh &> logfile &
# Makes PDF manual from many PNG TIF BMP GIF
# Files must be 600dpi or 300dpi Bitonal
# None, BZip, Fax, Group4, JPEG, JPEG2000, Lossless, LZW, RLE or Zip
# Version: ImageMagick 6.2.4 02/10/07 Q16
http://www.imagemagick.org
# Image info: identify -verbose 01_FC.tif
# apt-get install imagemagick
# apt-get install pdftk
# apt-get install libtiff-tools
# apt-get install gs-gpl
# The following command works in newer versions of imagemagick and quality 100 gives high compression
# convert $i -monochrome -compress Group4 -quality 100 -units PixelsPerInch -density 600 ${i%\.*}.pdf
echo Recompressing image files and making PDFs
for i in *.[PpBbTtGg][NnMmIiIi][GgPpFfFf]
do i_size=`wc -c < "$i"`
# The following intermediate conversion to gif bypasses an imagemagick 6.2 bug
convert -monochrome -compress None -units PixelsPerInch -density 600 $i temporary.gif
echo -n $i" SIZE="$i_size
convert -monochrome -compress Zip -quality 100 -units PixelsPerInch -density 600 temporary.gif temporary.png
png_size=`wc -c < "temporary.png"`
echo -n " PNG="$png_size
convert -monochrome -compress Group4 -quality 100 -units PixelsPerInch -density 600 temporary.gif temporary.tif
tif_size=`wc -c < "temporary.tif"`
echo -n " TIF="$tif_size
rm temporary.gif
if [ $png_size -lt $tif_size ]
then
rm temporary.tif
convert -compress Zip -quality 100 -units PixelsPerInch -density 600 temporary.png ${i%\.*}.pdf
o=${i%\.*}.png
rm $i
mv temporary.png $o
else
rm temporary.png
# The following imagemagick command would work in versions of imagemagick newer than 6.2:
# convert -compress Group4 -quality 100 -units PixelsPerInch -density 600 temporary.tif ${i%\.*}.pdf
# But we are using buggy OLD version imagemagick 6.2 so we have to do instead:
tiff2ps -2eaz temporary.tif > ${i%\.*}.ps
ps2pdf13 ${i%\.*}.ps
rm ${i%\.*}.ps
o=${i%\.*}.tif
rm $i
mv temporary.tif $o
fi
pdf_size=`wc -c < "${i%\.*}.pdf"`
echo " PDF="$pdf_size
done
echo Concatenating individual PDF files onto one big file
# The following imagemagick command would work but for bugs in imagemagick 6.2:
# convert *.pdf pdffile.pdf
# mv pdffile.pdf pdffile.fdp
# rm *.pdf
# mv pdffile.fdp pdffile.pdf
# But imagemagick OLD version 6.2 can't do this, so we must do the following instead.
pdftk *.pdf cat output temporary.fdp
rm *.pdf
mv temporary.fdp pdffile.pdf
out_size=`wc -c < "pdffile.pdf"`
echo "Finished compressing files and made pdffile.pdf $out_size"