Skip to content

Commit e692785

Browse files
committed
Merge branch 'develop' of github.com:OUDON/rmqr-generator into develop
2 parents 24110dd + a40ac61 commit e692785

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# An rMQR Code Generator
22
![Lorem_ipsum](https://user-images.githubusercontent.com/14174940/171996095-4707be09-506e-4ef2-ab90-9942d6efc2ed.png)
33

4-
This is an rMQR Code image generator implemented in Python.
4+
This is an rMQR Code image generator implemented in Python. This is implemented based on [ISO/IEC 23941:2022](https://www.iso.org/standard/77404.html).
55

66
## Important Notice
77
Please verify an image generated by this software whether it can decode correctly before use.

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def main():
2222
# print(qr)
2323

2424
# Save as png
25-
image = QRImage(qr)
25+
image = QRImage(qr, module_size=8)
2626
image.show()
2727
image.save("my_qr.png")
2828

src/rmqrcode/qr_image.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from .enums.color import Color
22

33
from PIL import Image
4+
from PIL import ImageDraw
45

56

67
class QRImage:
7-
def __init__(self, qr):
8-
self._img = Image.new('RGB', (qr.width() + 4, qr.height() + 4), (255, 255, 255))
8+
def __init__(self, qr, module_size=10):
9+
self._module_size = module_size
10+
self._img = Image.new(
11+
'RGB',
12+
((qr.width() + 4) * module_size, (qr.height() + 4) * module_size),
13+
(255, 255, 255)
14+
)
915
self._make_image(qr)
1016

1117

@@ -19,11 +25,15 @@ def save(self, name):
1925

2026

2127
def _make_image(self, qr):
28+
draw = ImageDraw.Draw(self._img)
2229
for y in range(qr.height()):
2330
for x in range(qr.width()):
2431
r, g, b = 125, 125, 125
2532
if qr.value_at(x, y) == Color.BLACK:
2633
r, g, b = 0, 0, 0
2734
elif qr.value_at(x, y) == Color.WHITE:
2835
r, g, b, = 255, 255, 255
29-
self._img.putpixel((x+2, y+2), (r, g, b))
36+
draw.rectangle(
37+
xy=((x + 2) * self._module_size, (y + 2) * self._module_size, (x + 1 + 2) * self._module_size, (y + 1 + 2) * self._module_size),
38+
fill=(r, g, b)
39+
)

0 commit comments

Comments
 (0)