Skip to content

Commit b593a2b

Browse files
committed
Fix embeded_* typo on paremeters
1 parent d2674f8 commit b593a2b

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

qrcode/image/styledpil.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StyledPilImage(qrcode.image.base.BaseImageWithDrawer):
2929
data integrity A resampling filter can be specified (defaulting to
3030
PIL.Image.Resampling.LANCZOS) for resizing; see PIL.Image.resize() for possible
3131
options for this parameter.
32-
The image size can be controlled by `embeded_image_ratio` which is a ratio
32+
The image size can be controlled by `embedded_image_ratio` which is a ratio
3333
between 0 and 1 that's set in relation to the overall width of the QR code.
3434
"""
3535

@@ -41,21 +41,22 @@ class StyledPilImage(qrcode.image.base.BaseImageWithDrawer):
4141

4242
def __init__(self, *args, **kwargs):
4343
self.color_mask = kwargs.get("color_mask", SolidFillColorMask())
44-
embeded_image_path = kwargs.get(
45-
"embeded_image_path",
46-
kwargs.get("embedded_image_path", None))
47-
self.embeded_image = kwargs.get(
48-
"embeded_image",
49-
kwargs.get("embedded_image", None))
50-
self.embeded_image_ratio = kwargs.get(
51-
"embeded_image_ratio",
52-
kwargs.get("embedded_image_ratio", 0.25))
53-
self.embeded_image_resample = kwargs.get(
54-
"embeded_image_resample",
55-
kwargs.get("embedded_image_resample", Image.Resampling.LANCZOS)
44+
# allow embeded_ parameters with typos for backwards compatibility
45+
embedded_image_path = kwargs.get(
46+
"embedded_image_path", kwargs.get("embeded_image_path", None)
5647
)
57-
if not self.embeded_image and embeded_image_path:
58-
self.embeded_image = Image.open(embeded_image_path)
48+
self.embedded_image = kwargs.get(
49+
"embedded_image", kwargs.get("embeded_image", None)
50+
)
51+
self.embedded_image_ratio = kwargs.get(
52+
"embedded_image_ratio", kwargs.get("embeded_image_ratio", 0.25)
53+
)
54+
self.embedded_image_resample = kwargs.get(
55+
"embedded_image_resample",
56+
kwargs.get("embeded_image_resample", Image.Resampling.LANCZOS),
57+
)
58+
if not self.embedded_image and embedded_image_path:
59+
self.embedded_image = Image.open(embedded_image_path)
5960

6061
# the paint_color is the color the module drawer will use to draw upon
6162
# a canvas During the color mask process, pixels that are paint_color
@@ -71,7 +72,7 @@ def new_image(self, **kwargs):
7172
"RGBA"
7273
if (
7374
self.color_mask.has_transparency
74-
or (self.embeded_image and "A" in self.embeded_image.getbands())
75+
or (self.embedded_image and "A" in self.embedded_image.getbands())
7576
)
7677
else "RGB"
7778
)
@@ -86,23 +87,23 @@ def init_new_image(self):
8687

8788
def process(self):
8889
self.color_mask.apply_mask(self._img)
89-
if self.embeded_image:
90-
self.draw_embeded_image()
90+
if self.embedded_image:
91+
self.draw_embedded_image()
9192

92-
def draw_embeded_image(self):
93-
if not self.embeded_image:
93+
def draw_embedded_image(self):
94+
if not self.embedded_image:
9495
return
9596
total_width, _ = self._img.size
9697
total_width = int(total_width)
97-
logo_width_ish = int(total_width * self.embeded_image_ratio)
98+
logo_width_ish = int(total_width * self.embedded_image_ratio)
9899
logo_offset = (
99100
int((int(total_width / 2) - int(logo_width_ish / 2)) / self.box_size)
100101
* self.box_size
101102
) # round the offset to the nearest module
102103
logo_position = (logo_offset, logo_offset)
103104
logo_width = total_width - logo_offset * 2
104-
region = self.embeded_image
105-
region = region.resize((logo_width, logo_width), self.embeded_image_resample)
105+
region = self.embedded_image
106+
region = region.resize((logo_width, logo_width), self.embedded_image_resample)
106107
if "A" in region.getbands():
107108
self._img.alpha_composite(region, logo_position)
108109
else:

qrcode/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,12 @@ def make_image(self, image_factory=None, **kwargs):
342342
343343
If the data has not been compiled yet, make it first.
344344
"""
345+
# allow embeded_ parameters with typos for backwards compatibility
345346
if (
346-
kwargs.get("embeded_image_path") or kwargs.get("embeded_image")
347+
kwargs.get("embedded_image_path")
348+
or kwargs.get("embedded_image")
349+
or kwargs.get("embeded_image_path")
350+
or kwargs.get("embeded_image")
347351
) and self.error_correction != constants.ERROR_CORRECT_H:
348352
raise ValueError(
349353
"Error correction level must be ERROR_CORRECT_H if an embedded image is provided"

qrcode/tests/test_qrcode_pil.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ def test_render_styled_Image():
5050
img.save(io.BytesIO())
5151

5252

53-
def test_render_styled_with_embeded_image():
54-
embeded_img = Image.new("RGB", (10, 10), color="red")
53+
def test_render_styled_with_embedded_image():
54+
embedded_img = Image.new("RGB", (10, 10), color="red")
5555
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
5656
qr.add_data(UNICODE_TEXT)
57-
img = qr.make_image(image_factory=StyledPilImage, embeded_image=embeded_img)
57+
img = qr.make_image(image_factory=StyledPilImage, embedded_image=embedded_img)
5858
img.save(io.BytesIO())
5959

6060

61-
def test_render_styled_with_embeded_image_path(tmp_path):
61+
def test_render_styled_with_embedded_image_path(tmp_path):
6262
tmpfile = str(tmp_path / "test.png")
63-
embeded_img = Image.new("RGB", (10, 10), color="red")
64-
embeded_img.save(tmpfile)
63+
embedded_img = Image.new("RGB", (10, 10), color="red")
64+
embedded_img.save(tmpfile)
6565
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
6666
qr.add_data(UNICODE_TEXT)
67-
img = qr.make_image(image_factory=StyledPilImage, embeded_image_path=tmpfile)
67+
img = qr.make_image(image_factory=StyledPilImage, embedded_image_path=tmpfile)
6868
img.save(io.BytesIO())
6969

7070

@@ -128,29 +128,29 @@ def test_embedded_image_and_error_correction(tmp_path):
128128
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_L)
129129
qr.add_data(UNICODE_TEXT)
130130
with pytest.raises(ValueError):
131-
qr.make_image(embeded_image_path=tmpfile)
131+
qr.make_image(embedded_image_path=tmpfile)
132132
with pytest.raises(ValueError):
133-
qr.make_image(embeded_image=embedded_img)
133+
qr.make_image(embedded_image=embedded_img)
134134

135135
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_M)
136136
qr.add_data(UNICODE_TEXT)
137137
with pytest.raises(ValueError):
138-
qr.make_image(embeded_image_path=tmpfile)
138+
qr.make_image(embedded_image_path=tmpfile)
139139
with pytest.raises(ValueError):
140-
qr.make_image(embeded_image=embedded_img)
140+
qr.make_image(embedded_image=embedded_img)
141141

142142
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_Q)
143143
qr.add_data(UNICODE_TEXT)
144144
with pytest.raises(ValueError):
145-
qr.make_image(embeded_image_path=tmpfile)
145+
qr.make_image(embedded_image_path=tmpfile)
146146
with pytest.raises(ValueError):
147-
qr.make_image(embeded_image=embedded_img)
147+
qr.make_image(embedded_image=embedded_img)
148148

149149
# The only accepted correction level when an embedded image is provided
150150
qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H)
151151
qr.add_data(UNICODE_TEXT)
152-
qr.make_image(embeded_image_path=tmpfile)
153-
qr.make_image(embeded_image=embedded_img)
152+
qr.make_image(embedded_image_path=tmpfile)
153+
qr.make_image(embedded_image=embedded_img)
154154

155155

156156
def test_shortcut():

0 commit comments

Comments
 (0)