import pymysql
from PIL import Image
import qrcode
class kqrcode(object):
"""docstring for ClassName"""
def __init__(self, arg):
super(kqrcode, self).__init__()
self.arg = arg
def get_data():
conn = pymysql.connect(user='root', passwd='admin',host='localhost', db='mytest',charset='utf8')
cur = conn.cursor()
cur.execute('call travel_gridpager(%s,%s)',(1,4))
for r in cur:
config={}
config['id']=str(r[0])
config['title']=str(r[1])
print("编号:"+str(r[0])+" 标题:"+str(r[1]))
url="http://192.168.5.121:8000/feelings/articles/44"+str(r[0])
kcount=kqrcode.create_qrcode(url,str(r[0]))
kqrcode.update_data(str(r[0]),"images/"+str(r[0])+".png")
cur.close()
conn.close()
def update_data(kid,erwei):
conn = pymysql.connect(user='root', passwd='admin',host='localhost', db='mytest',charset='utf8')
cur = conn.cursor()
cur.execute('call travel_erweibyid(%s,%s)',(kid,erwei))
cur.close()
conn.close()
def get_erweima(ipa,kid):
qr=qrcode.QRCode(version=1,error_correction=qrcode.constants.ERROR_CORRECT_L,box_size=8,border=8,)
qr.add_data(ipa)
qr.make(fit=True)
img=qr.make_image()
img = img.convert("RGBA")
img.save("images/"+kid+".png")
def create_qrcode(url, filename):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.ERROR_CORRECT_H,
box_size=10,
border=4,
)
qr.add_data(url)
qr.make(fit=True)
img = qr.make_image()
img = img.convert("RGBA")
icon = Image.open('images/xc.jpg')
w, h = img.size
factor = 4
size_w = int(w / factor)
size_h = int(h / factor)
icon_w, icon_h = icon.size
if icon_w > size_w:
icon_w = size_w
if icon_h > size_h:
icon_h = size_h
icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS)
w = int((w - icon_w) / 2)
h = int((h - icon_h) / 2)
icon = icon.convert("RGBA")
newimg = Image.new("RGBA", (icon_w + 8, icon_h + 8), (249, 205, 173))
img.paste(newimg, (w-4, h-4), newimg)
img.paste(icon, (w, h), icon)
img.save('images/' + filename + '.png', quality=100)
return 1