Here is a new way to generate a QR code in Python that meets the specifications of the Asset Administration Shell for the digital twin in the Industry 4.0.
A QR code to print out on paper (PDF 100 x 100 mm):
import qrcode
from PIL import Image
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm, inch
content='My QR-Code'
pixel=10
qrc=qrcode.QRCode(version=3,box_size=pixel,border=0)
qrc.add_data(content)
qrc.make(fit=True)
png=qrc.make_image(fill_color='black',back_color='white')
filepath='myqrcode.png'
png.save(filepath)
pic=Image.open(filepath)
width=pic.width
modules=width/pixel
linewidth=6
w=h=modules*linewidth
linewidth1=linewidth/2
xy=5*linewidth
a=9*linewidth+w
b=6*linewidth
a1=a-b
a2=b+linewidth
p=100*mm
z=25
def add_image(filepath):
page=(p,p)
c=canvas.Canvas('myqrcode.pdf',pagesize=page)
c.drawImage(filepath,xy+z,xy+z,width=w,height=h)
c.setLineWidth(linewidth)
c.setStrokeColorRGB(0,0,0,alpha=1)
c.rect(linewidth1+z,linewidth1+z,a,a,stroke=1,fill=0)
t=c.beginPath()
t.moveTo(a+z,linewidth+z)
t.lineTo(a1+z,linewidth+z)
t.lineTo(a+z,a2+z)
c.setFillColorRGB(0,0,0,alpha=1)
c.drawPath(t,fill=1,stroke=0)
c.save()
add_image(filepath)
(Remember to use proper indentation in Python)
Figure 1.