Help with Shell Script for printing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Silenus
Posts: 2
Joined: 2015-05-13T14:10:37-07:00
Authentication code: 6789

Help with Shell Script for printing

Post by Silenus »

Hi All,

I have a printing helper script that is called by my program when a screen shot is taken (using xwd) to print.

Here is what I want it to do:

1) Resize the image so it looks good on Landscape paper, regardless of the input image size
2) Prints a textual header above the input image
3) Prints a textual footer below the input image
4) Formats the output to be printed on a letter sized sheet of paper.

Here is what I currently have, and this IS working, I'm just wondering if there is a better way of doing this. One issue I am running into is the text is somewhat grainy on the printed page:

convert $xwdfile -resize 600x425 xwd:- | \
convert -background white -fill black -pointsize 14 \
-gravity center label:"$header" - -append xwd:- | \
convert - -background white -fill black -pointsize 14 \
-gravity center label:"$trailer" -append -page Letter \
-rotate 90 ps:- | \
lp -n$copies -d$printername -olandscape

In a nutshell, I am first resizing the image to 600x425, which is the smallest screenshot size generated. I then pipe that into convert to add the header. I then pipe it into convert a 3rd time to add the footer and prepare it for printing. Finally it is piped to the printer. The output printout is an image that is centered on the paper with about a 1.25 inch border all around, less the header and footer.

The other common screenshot size is 1200x888.

Can the above mess of convert commands be cleaned up some?
How about make it so the text header and footer look better?
Since 600x425 is the smallest image size, and likely to be the most common as well, is there a way to sharpen this up some when it is printed?

If it helps, here is what is going in for both small and large screenshots:

Small:

identify PrintFile
PrintFile XWD 600x425 600x425+0+0 8-bit sRGB 1.023MB 0.000u 0:00.009

Large:

identify PrintFileLg
PrintFileLg XWD 1200x888 1200x888+0+0 8-bit sRGB 4.266MB 0.010u 0:00.040

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with Shell Script for printing

Post by snibgo »

I don't know why you have three converts instead of just one.

How many pixels does your printer actually print? Perhaps around 3000x5000. So your printer driver will be resizing whatever you give it, to what the printer expects. A better (cleaner) result might come from choosing your resize to be closer to what the printer wants. Adjust the pointsizes accordingly.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with Shell Script for printing

Post by fmw42 »

First thing, what is your version of IM and what platform? Please always provide that, since syntax may differ. I presume you are on some kind of Unix platform from your command structure. Then also provide an example input image and the text you are using so someone can try to reproduce this. Also provide your output result.

Second, I see no reason to have more than one convert. IM has clones or MPR: in memory storage and parenthesis processing . Thus you can avoid all the converts and pipes and make one command line, except for the pipe to lp.

see
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/files/#mpr
Silenus
Posts: 2
Joined: 2015-05-13T14:10:37-07:00
Authentication code: 6789

Re: Help with Shell Script for printing

Post by Silenus »

I'm not sure either. I'm fairly green when it comes to imagemagick.

I had originally tried this using one command and annotate, however the text was scaled such that it looked horrible when printed.

This script was originally using a chain of commands of xwd2sb and plctrans to output the display to print, however upgrading old Linux terminals that were running at a color depth of 8 bits to new Linux terminals running with 24 bit color depth broke this script. I'm attempting to use ImageMagick to re-create the original functionality.

Printers vary as some are black and white laser printers, some are color laser printers, and some are inkjet printers. The BW Laser printers should output 5100x6600 (600 DPI). Scaling the image up yielded an image that was too large for the page, so it ended up getting clipped.

IM Version:

identify -version
Version: ImageMagick 6.8.6-9 August Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms ltdl lzma pango pangocairo png png tiff x xml zlib

OS Version:

HP-UX localhost B.11.23 U ia64 1784462845 unlimited-user license

The header is the display name and the footer is the date & time the display was printed. Nothing too fancy.

I'll post a link to sample images once I have them uploaded.

Thanks,
Post Reply