odoopython

python 生成二维码

2020-03-12  本文已影响0人  隔壁小红馆

用python生成临时文件夹存储二维码,c此处二维码作为图片储存,随后又自动删除文件夹

    def create_barcode(self, asset):
        from tempfile import TemporaryDirectory
        data = 'https://www.baidu.com'
        qr = qrcode.QRCode(version=1,
                           error_correction=qrcode.constants.ERROR_CORRECT_L,
                           box_size=10, border=4, )
        with TemporaryDirectory() as temp_folder:
            qr.add_data(data)
            qr.make(fit=True)
            img = qr.make_image()
            img.save(temp_folder+'\\barcode.jpg')
            asset_barcode = tools.image_resize_image_big(base64.b64encode(open(temp_folder + '\\barcode.jpg', 'rb').read()))
            return asset_barcode

炫酷二维码

看完记得点赞哦,笔芯

上一篇 下一篇

猜你喜欢

热点阅读