-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathprint-selphy-postcard
101 lines (87 loc) · 2.54 KB
/
print-selphy-postcard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# print-selphy-postcard
#
# Print postcard-sized (148x100mm, 5.8 x 3.9in) images
# on a Canon Selphy CP1200 and compatible photo printers
#
# Usage: print-selphy-postcard [--border] <file>
#
# This script requires ImageMagick, GNU sed and other text processing
# utilities, and CUPS.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Configuration parameters:
# Printer name
# Set Wi-Fi printer name, as seen by CUPS.
#
# Corresponding printer entry in CUPS configuration should be something like:
# dnssd://Canon%20SELPHY%20CP1200._ipp._tcp.local/?uuid=<uuid>
#
# To produce that entry for a new printer, use CUPS printer autodetection
# (usually http://localhost:631 , Administration / Add Printer menu) while
# mDNS service discovery is enabled.
#
PRINTER="Canon_SELPHY_CP1200"
# End of configuration parameters.
check="true"
for ex in \
identify convert grep tr head lpq lpr
do
loc=`which "${ex}"`
if [ "${loc}" = "" ]
then
echo "${ex} is missing"
check="false"
fi
done
if [ "${check}" = "false" ]
then
echo "Some utilities are missing"
exit 1
fi
lpq -P "${PRINTER}" >/dev/null 2>&1 || check="false"
if [ "${check}" = "false" ]
then
echo "Can't check printer ${PRINTER} status"
exit 1
fi
imggeom="1760x1190^"
if [ "${1}" = "--border" ]
then
shift 1
imggeom="1700x1130"
fi
if [ -f "${1}" ]
then
if \
echo $(($(identify "${1}" | tr ' ' '\n' | \
grep '^[0-9]\+x[0-9]\+$' | \
head -n 1 | tr 'x' '-'))) | \
grep -q -
then
rotateopt="-rotate"
rot="90"
else
rotateopt=""
rot=""
fi
convert ${rotateopt} ${rot} -define filter:blur=0.8 \
-filter Gaussian -resize "${imggeom}" \
-gravity center -extent "1760x1190" "${1}" png:- | \
convert -page "+46+34" -background white -flatten \
-extent "1872x1248" png:- -quality 97 jpg:- | \
lpr -o raw -P "${PRINTER}"
else
echo "No input file" 1>&2
exit 1
fi