[Techtalk] Mac or Linux for photo printing?

Conor Daly c.daly at met.ie
Mon Dec 18 13:09:37 UTC 2006


On Sun, Dec 17, 2006 at 11:11:30AM +0200 or thereabouts, Eeva Järvinen wrote:
> 
> I handled this once by using imagemagick + cups (lpr) on the command
> line.  The scripts took a list of image files on the command line and
> did some scaling and printing.
> 
> Now, what would be cool to have is a script that I could just drag the
> picture files into the script and have it print the pictures.  Sort of
> like specialized printer queues.

Inserting your own print filters into cups is pretty easy.  I did one for
psuedo-duplex with my single-sided printer.  It's simply a matter of
dropping your script into /usr/lib/cups/filter/<script-name> and modifying
a copy of the standard /usr/share/cups/model/postscript.ppd.gz to include
lines of the form:

*cupsFilter:    "application/vnd.cups-postscript 0 duplex-print"
*ModelName:     "Pseudo-Duplex Mode printer"
*ShortNickName: "Duplex Mode printer"
*NickName:      "Duplex Mode printer"

where "duplex-print" is the name of the filter script.  My "duplex-print"
filter uses one of the standard queues to print to and does the manipulation
beforehand (in my case with mpage and pstops).  It also does in-pipe
detection for use as a filter but can be used direct from the commandline.
Debug mode disables the printout.

Restart cups and add a new printer.  This particular filter knows nothing
about what is set in the ppd.  If you want to go there, there's a whole lot
more to know.  For your purposes, either make multiple scripts with
different parameters and make a print queue for each of them.  Then all you
need is the drag-and-drop functionality which may already be there in gnome
/ kde...

Conor

#!/bin/bash

########################################################################
#
# Program:      duplex-print
#
# Author:       Conor Daly <conor.daly at met.ie>
# Version:      0.1.1
# Date:         06 Dec 2006
#
# License:      GPL
#
# Purpose:
#               formats a document for printing in A4 duplex form.
#
#               uses the HP 2550 colour printer
#
#               takes input from stdin or as a file
#
#               we'll do nothing fancy here, just take the file and stuff it
#               through mpage and hand it to the printer
#
# Bugs:         Completely ignores any of the usual print accounting stuff
#               that comes in from lpr.
#
#########################################################################

# Set the print queue to use.  It must be capable of duplex printing or
# you won't get sensible output
PRINTER1=2550		# standard printer queue
PRINTER2=2550m		# maunal feed printer queue
PRINTER1_COMMAND="lpr -P${PRINTER1}"
PRINTER2_COMMAND="lpr -P${PRINTER2}"

# For debug info, uncomment the "LOGFILE=" line below
# Note: debug will disable actual printout and will leave
# output in /tmp/book1.ps and /tmp/book2.ps...
#LOGFILE=/var/log/cups/duplex.log

# Start the print run...
[ $LOGFILE ] && echo >> $LOGFILE
[ $LOGFILE ] && echo "________________________________________________" >>
$LOGFILE
[ $LOGFILE ] && echo -n "Starting print run at: " >> $LOGFILE
[ $LOGFILE ] && date >> $LOGFILE
[ $LOGFILE ] && echo $0 $* >> $LOGFILE

MPAGE1_SWITCH="-j 2%2"
MPAGE2_SWITCH="-r -j 1%2"

# pipe or console?
if [ -t 0 ]; then
  # We're in a console here
  [ $LOGFILE ] && echo "console">> $LOGFILE
  FILE=$1
  PIPE=
else
  # Here, we're in a pipe
  # We need a temporary file here so something else can carry on
  [ $LOGFILE ] && echo "pipe">> $LOGFILE
  FILE=/tmp/duplex-print$$.tmp
  cat > $FILE
  PIPE=1
fi

# Find out how many pages to print
NUM=`mpage -1 $FILE | grep %%Pages: | tail -1 | cut -f2 -d" "`
[ $LOGFILE ] && echo "Processing ${NUM} pages from ${FILE}..." >> $LOGFILE

# Just see where mpage is...
[ $LOGFILE ] && which mpage >> $LOGFILE

# Now, push $FILE through mpage and on to the printer
[ $LOGFILE ] || mpage -1 -$MPAGE1_SWITCH bA4 $FILE | ${PRINTER1_COMMAND}
[ $LOGFILE ] || mpage -1 -$MPAGE2_SWITCH bA4 $FILE | ${PRINTER2_COMMAND}

# or just generate debug output
[ $LOGFILE ] && echo "mpage -1 $MPAGE1_SWITCH -bA4 $FILE" >> $LOGFILE
[ $LOGFILE ] && echo "mpage -1 $MPAGE2_SWITCH -bA4 $FILE" >> $LOGFILE
[ $LOGFILE ] && mpage -1 $MPAGE1_SWITCH -bA4 $FILE > /tmp/book1.ps
[ $LOGFILE ] && mpage -1 $MPAGE2_SWITCH -bA4 $FILE > /tmp/book2.ps

[$LOGFILE] && chmod 644 /tmp/book?.ps

# If the file came down a pipe, delete the temporary file
[ $LOGFILE ] && [ "X${PIPE}" == "X1" ] && echo "Removing $FILE" >> $LOGFILE
if [ ! $LOGFILE ]; then
  [ "X$PIPE" == "X1" ] && rm -f $FILE
fi

-- 
Conor Daly,                   
Met Eireann, Glasnevin Hill,  
Dublin 9, Ireland             
Ph +3531 8064276 Fax +3531 8064247

*********************************************************************************
This e-mail and any files transmitted with it are confidential and intended solely for the addressee. If you have received this email in error please notify the sender.
This e-mail message has also been scanned for the presence of computer viruses.

Ta an riomhphost seo, agus aon chomhad ata nasctha leis, faoi run agus is don te a seoladh chuige amhain e. Ma tharla go bhfuair tu an riomhphost seo tri dhearmad cuir in iul don te a sheol e led' thoil.

Ta an teachtaireacht riomhphoist seo scuabtha le bogearrai frithvireas.
********************************************************************************
NorthBridge Mail Server id e9yrhg43fncvj3974vjenw



More information about the Techtalk mailing list