Created
May 21, 2012 03:17
-
-
Save pcostesi/2760420 to your computer and use it in GitHub Desktop.
QRCode cli printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qrcode.image.base | |
BLACK = "\033[40m" | |
WHITE = "\033[107m" | |
DEFAULT = "\033[49m" | |
SPACER = " " | |
class CliImage(qrcode.image.base.BaseImage): | |
"""Cli image builder.""" | |
def __init__(self, border, width, box_size): | |
super(CliImage, self).__init__(border, width, box_size) | |
size = (self.width + border * 2) | |
self.border = border | |
self.width = width | |
self.lines = [[WHITE] * (size + 1) for i in xrange(size)] | |
def drawrect(self, row, col): | |
self.lines[row + self.border][col + self.border] = BLACK | |
def save(self, stream, kind=None): | |
stream.write(self.to_string()) | |
def to_string(self): | |
return ('\n'.join(SPACER.join(l) + DEFAULT for l in self.lines)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment