forked from ergosteur/xkcdprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xkcdprint.py
31 lines (28 loc) · 821 Bytes
/
xkcdprint.py
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
#!/usr/bin/python
import escpos
import escpos.printer
import PythonMagick
import xkcd
import textwrap
nComicsToPrint = 2
nComicsPrinted = 0
p = escpos.printer.Usb(0x04b8,0x0e15)
nLatestComic = xkcd.getLatestComic().number
while nComicsPrinted < nComicsToPrint:
comic = xkcd.getComic(nLatestComic - nComicsPrinted)
comicImg = comic.download()
comicAltText = textwrap.wrap(comic.getAsciiAltText(),40)
img = PythonMagick.Image(comicImg.encode('utf-8'))
if (img.size().width() > img.size().height()):
img.rotate(90)
img.resize('512x')
else:
img.resize('512x')
img.magick('PNG')
img.write('outputImage.png')
p.image('outputImage.png')
p.text('\n')
for line in comicAltText:
p.text('\n' + line)
p.cut()
nComicsPrinted = nComicsPrinted + 1