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

Jonny Flowers
  • 631
  • 1
  • 9
  • 20

1 Answers1

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.

Ikke
  • 99,403
  • 23
  • 97
  • 120
  • 1
    There is nice tutorial with examples [here](http://nadiana.com/pil-tutorial-basic-advanced-drawing#Drawing_Text). – unutbu Sep 09 '12 at 11:59
  • I cant figure out how to add whitespace to the image to add text as the qrcode library outputs just a single image. – Jonny Flowers Sep 09 '12 at 15:19
  • According to [this](http://stackoverflow.com/questions/1572691/in-python-python-image-library-1-1-6-how-can-i-expand-the-canvas-without-resiz) answer, you can best just create a new image with the required size and paste the old image into that. – Ikke Sep 09 '12 at 15:34
  • Can it append text to SVG? – digz6666 Jan 22 '16 at 04:22