forked from lincolnloop/python-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure.py
More file actions
56 lines (44 loc) · 1.49 KB
/
pure.py
File metadata and controls
56 lines (44 loc) · 1.49 KB
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
from itertools import chain
from qrcode.compat.png import PngWriter
from qrcode.image.base import BaseImage
class PyPNGImage(BaseImage):
"""
pyPNG image builder.
"""
kind = "PNG"
allowed_kinds = ("PNG",)
needs_drawrect = False
def new_image(self, **kwargs):
if not PngWriter:
raise ImportError("PyPNG library not installed.")
return PngWriter(self.pixel_size, self.pixel_size, greyscale=True, bitdepth=1)
def drawrect(self, row, col):
"""
Not used.
"""
def save(self, stream, kind=None):
if isinstance(stream, str):
stream = open(stream, "wb")
self._img.write(stream, self.rows_iter())
def rows_iter(self):
yield from self.border_rows_iter()
border_col = [1] * (self.box_size * self.border)
for module_row in self.modules:
row = (
border_col
+ list(
chain.from_iterable(
([not point] * self.box_size) for point in module_row
)
)
+ border_col
)
for _ in range(self.box_size):
yield row
yield from self.border_rows_iter()
def border_rows_iter(self):
border_row = [1] * (self.box_size * (self.width + self.border * 2))
for _ in range(self.border * self.box_size):
yield border_row
# Keeping this for backwards compatibility.
PymagingImage = PyPNGImage