-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
29 lines (21 loc) · 717 Bytes
/
code.py
File metadata and controls
29 lines (21 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pyqrcode
from PIL import Image
# Generate the qr code and save as png
qrobj = pyqrcode.create('https://google.com')
with open('test.png', 'wb') as f:
qrobj.png(f, scale=10)
# Now open that png image to put the logo
img = Image.open('test.png')
width, height = img.size
# How big the logo we want to put in the qr code png
logo_size = 100
# Open the logo image
logo = Image.open('s.jpg')
# Calculate xmin, ymin, xmax, ymax to put the logo
xmin = ymin = int((width / 2) - (logo_size / 2))
xmax = ymax = int((width / 2) + (logo_size / 2))
# resize the logo as calculated
logo = logo.resize((xmax - xmin, ymax - ymin))
# put the logo in the qr code
img.paste(logo, (xmin, ymin, xmax, ymax))
img.show()