2

I have a python read a serial port and then create a QR code from this data. What I want to do is add the data used to make the QR code into the image that is generated.

qr = qrcode.QRCode(
    version=1,
    box_size=10,
)
data1 = arduino.readline()
shadata1 = hashlib.sha1(data1).hexdigest()

qrdata = data1 + shadata1[0] + shadata1[1] + shadata1[2] + shadata1[3] + shadata1[4] + shadata1[5]
qr.add_data(qrdata)
qr.make(fit=True)

img = qr.make_image()
img_file = "/" + data1 + ".png"
img.save(img_file, 'PNG')

So at the moment I get a QR code generated and saved, I want to have the following

 _____________
|             |  "Title"
|             |  Data1
|             |  "Pin Code"
|             |  shadata1[0] shadata1[1] shadata1[2] shadata1[3] shadata1[4] shadata1[5]
|             |
|_____________|

I have no idea how I would actually carry that out.

Thanks

1 Answer 1

3

With the Python Image Library you can manipulate images, including adding text to them.

Note that the PIL is only available for Python 2.x. v3 support is on it's way.

Sign up to request clarification or add additional context in comments.

4 Comments

There is nice tutorial with examples here.
I cant figure out how to add whitespace to the image to add text as the qrcode library outputs just a single image.
According to this answer, you can best just create a new image with the required size and paste the old image into that.
Can it append text to SVG?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.