Skip to content
Snippets Groups Projects
Verified Commit fdd3968f authored by David Beniamine's avatar David Beniamine
Browse files

Reduce image size to avoid error on small data

parent 1e2c58d2
No related branches found
No related tags found
No related merge requests found
...@@ -22,16 +22,6 @@ def getCard(first, last, data): ...@@ -22,16 +22,6 @@ def getCard(first, last, data):
def genQr(data, output, colors=('black', 'white'), logo_path=None): def genQr(data, output, colors=('black', 'white'), logo_path=None):
if logo_path is not None:
logo = Image.open(logo_path)
# taking base width
basewidth = 100
# adjust image size
wpercent = (basewidth/float(logo.size[0]))
hsize = int((float(logo.size[1])*float(wpercent)))
logo = logo.resize((basewidth, hsize), Image.ANTIALIAS)
QRcode = qrcode.QRCode() QRcode = qrcode.QRCode()
# adding URL or text to QRcode # adding URL or text to QRcode
...@@ -45,6 +35,14 @@ def genQr(data, output, colors=('black', 'white'), logo_path=None): ...@@ -45,6 +35,14 @@ def genQr(data, output, colors=('black', 'white'), logo_path=None):
img = QRcode.make_image(fill_color=fill, back_color=back).convert('RGB') img = QRcode.make_image(fill_color=fill, back_color=back).convert('RGB')
if logo_path is not None: if logo_path is not None:
logo = Image.open(logo_path)
# taking base width
basewidth = min(int(10 * img.width / 100), 100)
# adjust image size
wpercent = (basewidth/float(logo.size[0]))
hsize = int((float(logo.size[1])*float(wpercent)))
logo = logo.resize((basewidth, hsize), Image.ANTIALIAS)
# set size of QR code # set size of QR code
pos = ((img.size[0] - logo.size[0]) // 2, pos = ((img.size[0] - logo.size[0]) // 2,
(img.size[1] - logo.size[1]) // 2) (img.size[1] - logo.size[1]) // 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment