python script to generate images of a QRCode made of text character in the Cells
This commit is contained in:
parent
48b4df3881
commit
c2b92f18af
|
@ -0,0 +1,62 @@
|
|||
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="white" if (letter == '█') else "grey"
|
||||
# drawing a box if the letter is █
|
||||
if (letter == '█'):
|
||||
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")
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 173 KiB |
Binary file not shown.
After Width: | Height: | Size: 351 B |
Binary file not shown.
After Width: | Height: | Size: 583 B |
Loading…
Reference in New Issue