[PLUG] QR Code generator with text label

Bill Barry bill at billbarry.org
Sun May 31 15:41:23 UTC 2015


On Sat, May 30, 2015 at 10:59 PM, Chuck Hast <wchast at gmail.com> wrote:
> Qrencode (cmd line tool) generates png files, Qreator (gui tool) generates
> png files too. I think I will see if I can take a look at the source of
> qreator and
> see how hard it might be to "bend" it to do a line of text adjacent to the
> QR
> code. If I can do that, i have my solution, put it on some older computers
> and
> add a label printer and done. The Brother QL-570 will work quite well and
> Brother has a nice set of Linux/Unix drivers for their products. Worse case
> is
> I create the QR codes and use Gimp to put them into something that has a
> text line on it , then turn the whole thing into a small file to be
> printed. I do
> one for each piece of hardware I need to label.
>

Here is a python script I wrote a while back that does something like
you want.. The QR code is a URL (https://example.com/stuff/rack/1) and
there is some txt  "rack 1" underneath it. It has been a while since I
wrote it, so it looks like gibberish to me.

Bill

from PIL import Image, ImageDraw,ImageFont
import qrcode

qr = qrcode.QRCode(
    version=3,
    error_correction=qrcode.constants.ERROR_CORRECT_Q,
    box_size=10,
    border=4,
    )

image  = Image.new( "RGBA", ( 410, 480 ) ,"white");

qr.add_data('https://example.com/stuff/rack/1')
qr.make(fit=True)

img = qr.make_image()
print img.size
image.paste(img, (0,0), img.convert("RGBA") );


draw = ImageDraw.Draw(image)
font = ImageFont.truetype("/usr/lib/cinelerra/fonts/arial.ttf",60)
#font = ImageFont.load_default()
txt = "rack 1"
draw.text((100, 410), txt, (0,0,0), font=font)


image.save("qr.png")



More information about the PLUG mailing list