标签:
PIL和QRCode下载地址:
http://www.pythonware.com/products/pil/ https://pypi.python.org/pypi/qrcode/5.1 #你可能需要的setuptools: https://pypi.python.org/pypi/setuptools/
参考文档:
http://www.cnblogs.com/linjiqin/p/4140455.html http://www.cnblogs.com/ryuham/p/4455954.html
代码示例:
#-*- coding:utf8 -*- import qrcode import PIL if __name__ == ‘__main__‘: blog_url = ‘http://www.cnblogs.com/lichmama‘ #初始化二维码生成器 code_maker = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H) #填入在二维码中保存的数据 code_maker.add_data(blog_url) code_maker.make(fit=True) code_image = code_maker.make_image() code_image = code_image.convert(‘RGBA‘) face_image = PIL.Image.open(r‘lichmama.png‘) code_width, code_height = code_image.size face_image = face_image.resize((100,100), PIL.Image.ANTIALIAS) #将头像嵌入二维码当中 code_image.paste(face_image, ((code_width-100)/2, (code_height-100)/2)) code_image.save(r‘qrcode.png‘)
生成图片:
标签:
原文地址:http://www.cnblogs.com/lichmama/p/4631180.html