@@ -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 :
0 commit comments