@staticmethod<EOL><INDENT>def _insert_img(qr_img, icon_img=None, factor=<NUM_LIT:4>, icon_box=None, static_dir=None):<DEDENT>
img_w, img_h = qr_img.size<EOL>size_w = int(img_w) / int(factor)<EOL>size_h = int(img_h) / int(factor)<EOL>try:<EOL><INDENT>icon_fp = os.path.join(icon_img)<EOL>if static_dir:<EOL><INDENT>icon_fp = os.path.join(static_dir, icon_img)<EOL><DEDENT>if icon_img.split("<STR_LIT>")[<NUM_LIT:0>] in ["<STR_LIT:http>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>icon_fp = BytesIO(urlopen(icon_img).read())  <EOL><DEDENT>icon = Image.open(icon_fp)<EOL><DEDENT>except:<EOL><INDENT>return qr_img<EOL><DEDENT>icon_w, icon_h = icon.size<EOL>icon_w = size_w if icon_w > size_w else icon_w<EOL>icon_h = size_h if icon_h > size_h else icon_h<EOL>icon = icon.resize((int(icon_w), int(icon_h)), Image.ANTIALIAS)<EOL>icon = icon.convert("<STR_LIT>")<EOL>left = int((img_w - icon_w) / <NUM_LIT:2>)<EOL>top = int((img_h - icon_h) / <NUM_LIT:2>)<EOL>icon_box = (int(icon_box[<NUM_LIT:0>]), int(icon_box[<NUM_LIT:1>])) if icon_box else (left, top)<EOL>qr_img.paste(im=icon, box=icon_box, mask=icon)<EOL>return qr_img<EOL>
Inserts a small icon to QR Code image