import io import math # Importing Image and ImageFont, ImageDraw module from PIL package from PIL import Image, ImageFont, ImageDraw #import QRcode generator lib import qrcode #set the text and the code here text = "█SLHJD!■C■KOQFHY■PKJSOOFH■BY■ONDTTX■GRC■ADLYJ■ZBSH■SOITRM●JKUHSOK●ZA■MAOLH■RVHRPJ!■█" code = "TCHERNOBYL" #3💪+1👒+2👕+1🧥+1🧣+1🔫+4👂=🤠+❓TCHERNOBYL textsize = 30 #px #generate QRCode qr = qrcode.QRCode( version=1, #smallest error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=0, ) qr.add_data(code) #saving the normal QRCode image img = qr.make_image() type(img) # qrcode.image.pil.PilImage img.save("qrcode.png") #storing the qrCode in a list[list[bool]] boolmatrix = qr.get_matrix() # creating a image object codeximage = Image.new("RGB", (textsize*len(boolmatrix), textsize*len(boolmatrix)), "white") codexdraw = ImageDraw.Draw(codeximage) # specified font size fontnormal = ImageFont.truetype(r'./FiraMono_Regular.otf', textsize) fontbold = ImageFont.truetype(r'./FiraMono_Bold.otf', textsize) # drawing text index = 0 for i, inner_list in enumerate(boolmatrix): for j, element in enumerate(inner_list): # get the letter in the text letter = text[index%len(text)] # set the font and the color according to the QRCode cell bool value if(element): font=fontbold color="black" else: font=fontnormal color="grey" # drawing a black box if the letter is █ if (letter == '█'): if (element): codexdraw.rectangle([(j*textsize, i*textsize), (j*textsize+textsize, i*textsize+textsize)] , fill =color) # drawing the letter else: codexdraw.multiline_text((j*textsize+textsize/5, i*textsize-textsize/10), letter, fill =color, font =font, spacing=0, align ="left") index+=1 #saving the codex QRCode image with the text in the cells codeximage.save("codex.png")