AttributeError: 'NoneType' object has no attribute 'getdraw' #6743
Answered
by
radarhere
jegan221724
asked this question in
Q&A
-
I'm new to coding and trying to generate multiple QR codes for multiple links with a logo and custom text for each link. On executing I'm getting the below attached error. I could not find anyone reporting this issue anywhere, is there anything wrong with my code? Please help. Code is as below: import qrcode
from PIL import ImageDraw, ImageFont, Image
from fpdf import FPDF
import os
from PIL import ImageDraw
from PIL import ImageFont
from qrcode.main import QRCode
n = 100
ser = 'KA0'
png = ".png"
for i in range(11, n):
# Creating an instance of QRCode class
Logo_link = r'C:\Python_Projects\Neer_Project\just_logo_whit_bg.png'
logo = Image.open(Logo_link)
# taking base width
basewidth = 100
# adjust image size
wpercent = (basewidth / float(logo.size[0]))
hsize = int((float(logo.size[1]) * float(wpercent)))
logo = logo.resize((basewidth, hsize), Image.ANTIALIAS)
QRdata = qrcode.QRCode(
error_correction=qrcode.constants.ERROR_CORRECT_H
)
# adding URL or text to QRcode
qr = qrcode.QRCode(box_size=20)
QRdata.add_data("https://www.example.org/product-page/" + (ser + str(i)))
# generating QR code
QRdata.make()
# taking color name from user
QRcolor = 'Black'
# adding color to QR code
QRimg = QRdata.make_image(
fill_color=QRcolor, back_color="white").convert('RGB')
# set size of QR code
pos = ((QRimg.size[0] - logo.size[0]) // 2,
(QRimg.size[1] - logo.size[1]) // 2)
Qr_final = QRimg.paste(logo, pos)
draw = ImageDraw.Draw(Qr_final)
font = ImageFont.truetype("QR font tfb.ttf", 30)
draw.text((300, 520), ser + str(i), font=font)
draw.text((300,550),'Adopt Me!', font=font)
# save the QR code generated
Qr_final.save(ser + str(i) + png)
print('QR code generated!') Error I got:
|
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
Nov 16, 2022
Replies: 1 comment 6 replies
-
Hi. Qr_final = QRimg.paste(logo, pos)
draw = ImageDraw.Draw(Qr_final) Instead, just use QRimg.paste(logo, pos)
draw = ImageDraw.Draw(QRimg)
# ...
# save the QR code generated
QRimg.save(ser + str(i) + png) |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
jegan221724
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
paste()
doesn't return a new image, it just alters the image that it is being called on. So you are settingQr_final
toNone
in the following code.Instead, just use
QRimg
.