Created
September 1, 2017 00:07
-
-
Save uhho/5a2cc7326cea830eeb644eb89c36f465 to your computer and use it in GitHub Desktop.
Generating QR code with image at the center.
This file contains hidden or 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
import pyqrcode | |
from PIL import Image | |
# create background - QR code | |
qr = pyqrcode.create('Some text',error = 'H') | |
qr.png('output.png', scale=10) | |
im = Image.open('output.png') | |
im = im.convert("RGBA") | |
# open image | |
logo = Image.open('logo.png') | |
# position of the image | |
box = (135,135,235,235) | |
im.crop(box) | |
region = logo | |
region = region.resize((box[2] - box[0], box[3] - box[1]), Image.ANTIALIAS) | |
# merging background and image | |
# passing image as a third parameter enables transparency | |
im.paste(region, box, region) | |
im.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment