def make_qr_code_image(text: Any, qr_code_options: QRCodeOptions) -> bytes: """ Returns a bytes object representing a QR code image for the provided text. :param str text: The text to encode :param qr_code_options: Options to create and serialize the QR code. :rtype: bytes """ qr = make_qr(text, qr_code_options) out = io.BytesIO() qr.save(out, **qr_code_options.kw_save()) return out.getvalue()
def make_embedded_qr_code(text: Any, qr_code_options: QRCodeOptions) -> str: """ Generates a <svg> or <img> tag representing the QR code for the given text. This tag can be embedded into an HTML document. """ qr = make_qr(text, qr_code_options) kw = qr_code_options.kw_save() # Pop the image format from the keywords since qr.png_data_uri / qr.svg_inline # set it automatically kw.pop('kind') if qr_code_options.image_format == 'png': return mark_safe('<img src="{0}" alt="{1}">' .format(qr.png_data_uri(**kw), escape(text))) return mark_safe(qr.svg_inline(**kw))