Last active
February 4, 2020 12:19
-
-
Save cstrouse/01b2f7469a40deda1a3f8b33f00ca36b to your computer and use it in GitHub Desktop.
This was a quick and dirty example used for an Upwork proposal requesting generating a QR code and using it to create a composite image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
from io import BytesIO | |
import cairosvg | |
import pyqrcode | |
from PIL import Image | |
url = pyqrcode.create('https://github.com/cstrouse/') | |
url.svg('upwork-qrcode.svg', scale=16, module_color='black') | |
out = BytesIO() | |
cairosvg.svg2png(url='upwork-qrcode.svg', write_to=out) | |
fg = Image.open(out) | |
bg = Image.open('BaseImage.png') | |
#print(url.terminal(quiet_zone=1)) | |
offset = ((bg.size[0] - fg.size[0])//2, (bg.size[1] - fg.size[1])//3) | |
bg.paste(fg, offset, fg.convert('RGBA')) | |
bg.save('test.png', 'PNG') | |
os.unlink('upwork-qrcode.svg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cairocffi==1.1.0 | |
CairoSVG==2.4.2 | |
cffi==1.13.2 | |
Pillow==6.2.1 | |
pypng==0.0.20 | |
PyQRCode==1.2.1 |
Author
cstrouse
commented
Feb 4, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment