Skip to content

Instantly share code, notes, and snippets.

@uhho
Created September 1, 2017 00:07
Show Gist options
  • Save uhho/5a2cc7326cea830eeb644eb89c36f465 to your computer and use it in GitHub Desktop.
Save uhho/5a2cc7326cea830eeb644eb89c36f465 to your computer and use it in GitHub Desktop.
Generating QR code with image at the center.
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