Created
July 27, 2014 22:14
-
-
Save caetanus/205e4ebb84841b2633e7 to your computer and use it in GitHub Desktop.
bitmap printing for cb55-c
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
def prepare_bitmap(self, bitmap, align="left"): | |
bitmap = bitmap.convert("1") | |
width = self._bitmap_res\ | |
if bitmap.size[0] > self._bitmap_res else bitmap.size[0] | |
height = bitmap.size[1] | |
if width < bitmap.size[0]: | |
bitmap = bitmap.crop((0, 0, width, height)) | |
bitmap_output = Image.new("1", (self._bitmap_res, height), | |
0xFF #background color | |
) | |
bitmap.output.paste(bitmap, bitmap.size) | |
if align == "right": | |
bitmap_output = bitmap_output.offset(self._bitmap_res - width/2, 0) | |
elif align == "center": | |
bitmap_output = bitmap_output.offset(self._bitmap_res/2 - width/2, 0) | |
page_width = (self._bitmap_res/8) | |
bitmap_lenght = bitmap_output.size[0] * bitmap_output.size[0] | |
bitmap_lenght = struct.pack(">H", bitmap_lenght) | |
out = ["\x1b*%c%s" % (page_width, bitmap_lenght)] | |
out += map(self.invbyte, bitmap_output.tostring()) | |
output = ''.join(out) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment