Skip to content

Commit 68f3b29

Browse files
committed
Raise error if embedded image is provided and error correction is lower than H
1 parent ffa2b4a commit 68f3b29

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

qrcode/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,12 @@ def make_image(self, image_factory=None, **kwargs):
345345
346346
If the data has not been compiled yet, make it first.
347347
"""
348-
if kwargs.get("embeded_image_path") and self.error_correction != constants.ERROR_CORRECT_H:
349-
raise ValueError("Error correction level must be ERROR_CORRECT_H if an embedded image is provided")
348+
if (
349+
kwargs.get("embeded_image_path") or kwargs.get("embeded_image")
350+
) and self.error_correction != constants.ERROR_CORRECT_H:
351+
raise ValueError(
352+
"Error correction level must be ERROR_CORRECT_H if an embedded image is provided"
353+
)
350354
_check_box_size(self.box_size)
351355
if self.data_cache is None:
352356
self.make()

qrcode/tests/test_qrcode_pil.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_render_styled_Image():
5252

5353
def test_render_styled_with_embeded_image():
5454
embeded_img = Image.new("RGB", (10, 10), color="red")
55-
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_L)
55+
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
5656
qr.add_data(UNICODE_TEXT)
5757
img = qr.make_image(image_factory=StyledPilImage, embeded_image=embeded_img)
5858
img.save(io.BytesIO())
@@ -129,21 +129,28 @@ def test_embedded_image_and_error_correction(tmp_path):
129129
qr.add_data(UNICODE_TEXT)
130130
with pytest.raises(ValueError):
131131
qr.make_image(embeded_image_path=tmpfile)
132+
with pytest.raises(ValueError):
133+
qr.make_image(embeded_image=embedded_img)
132134

133135
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_M)
134136
qr.add_data(UNICODE_TEXT)
135137
with pytest.raises(ValueError):
136138
qr.make_image(embeded_image_path=tmpfile)
139+
with pytest.raises(ValueError):
140+
qr.make_image(embeded_image=embedded_img)
137141

138142
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_Q)
139143
qr.add_data(UNICODE_TEXT)
140144
with pytest.raises(ValueError):
141145
qr.make_image(embeded_image_path=tmpfile)
146+
with pytest.raises(ValueError):
147+
qr.make_image(embeded_image=embedded_img)
142148

143149
# The only accepted correction level when an embedded image is provided
144150
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
145151
qr.add_data(UNICODE_TEXT)
146152
qr.make_image(embeded_image_path=tmpfile)
153+
qr.make_image(embeded_image=embedded_img)
147154

148155

149156
def test_shortcut():

0 commit comments

Comments
 (0)