Skip to content

Instantly share code, notes, and snippets.

@cstrouse
Last active February 4, 2020 12:19
Show Gist options
  • Save cstrouse/01b2f7469a40deda1a3f8b33f00ca36b to your computer and use it in GitHub Desktop.
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.
#!/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')
cairocffi==1.1.0
CairoSVG==2.4.2
cffi==1.13.2
Pillow==6.2.1
pypng==0.0.20
PyQRCode==1.2.1
@cstrouse
Copy link
Author

cstrouse commented Feb 4, 2020

test
BaseImage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment