QR code with type



  • I was hoping to find a way to use drawbot to create a minimal, typographic QR code.

    I saw this post: https://forum.drawbot.com/topic/274/qrcodegenerator-size-message?_=1647813283414

    which uses apple's QRCodeGenerator and converts the image to pixels. I was hoping to do something more like ASCII art, so I could use my own typeface for the squares.

    I found this library: https://github.com/lincolnloop/python-qrcode
    which takes an argument --ascii

    qr --ascii "Some data" > "test.txt"
    
    

    and that outputs as box drawing characters (not actually ASCII) to represent 2 lines at a time. Eg. it uses U+2588 █, U+x2580 ▀, or U+2584 ▄. But this isn't quite what I'm looking for.

    What I would like to do is instead parse this same data into single lines (not double) and represent it with something like /H and /space, or ⬛ and ▢. But I'm struggling to figure this one out. Has anyone here done something like this? Or have any suggestions? Even better if I can isolate out the corner finder patterns separately (see attached example)

    Thanks so much!
    CJ

    qr text example


  • admin

    expanding Gustavo's example:

    import colorsys
    
    path = bytes('http://www.drawbot.com/', 'utf-8')
    
    w, h = 31, 31
    s = 10
    
    size(w*s, h*s)
    
    img = ImageObject()
    img.QRCodeGenerator((w, h), path, 'Q')
    
    iw, ih = img.size()
    
    t = ""
    
    for y in reversed(range(int(ih))):
        for x in range(int(iw)):
            r, g, b, a = imagePixelColor(img, (x, y))
            _, l, _ = colorsys.rgb_to_hls(r, g, b)
            if l < 0.51:
                fill(0)            
                rect(x*s, y*s, s, s)
                t += "W"
            else:
                t += " "
        
        t += "\n"
    
    newPage()
    font("Menlo", 16)
    lineHeight(10)
    textBox(t, (0, 0, width(), height()))
    print(t)
    

    and the corners are always the same 🙂



  • @frederik this works, thanks so much!



  • Hello fellow Drawboteers
    I'm also trying to generate some QR-Codes. And these two posts already helped me get on the right track.

    But now I can't figure out how to create a more complex QR-Code for a longer string (with 57x57 grid). I don't understand the relation between string-length and the specified "w, h" variables. Given the example on Apple Developer it should be possible to create more complex codes with QRCodeGenerator...

    Any help is appreciated! Thank you.


Log in to reply