Tuesday, December 25, 2018

flask response svg or png qrcode generator using pyqrcode module

import pyqrcode, png
text = pyqrcode.create('')
text.svg('./app/static/uploads/uca-url.svg', scale=8)
text.png('./app/static/uploads/uca-url.png', scale=8)
# print(text.text())
# print(text.terminal(module_color='red', background='yellow'))
# print(url.terminal(quiet_zone=1))


@users_api.route('/')
def base_index():
import io
import pyqrcode, png
qr = pyqrcode.create('5035265994')
qr.png('test.png', scale=8)
image_binary = io.open("test.png", "rb")
print('***********type is ', type(image_binary))
response = make_response(image_binary.read())
response.headers.set('Content-Type', 'image/png')
# response.headers.set('Content-Disposition', 'attachment', filename='test.png')
return response
# return json_error(), 404

No comments: