Fancy QR Code Award - Come and show your exclusive QR code

foreword

I saw the Nuggets Creative Development Competition recently, and I came up with the theme on the spot, QR code!

Two-dimensional code can be said to be the most commonly used in our life, payment, scan code login, information registration.... Especially in the past three years of epidemic, where can't scan a health treasure, I almost feel sick, then Why don't we show off our creativity and make some fancy QR codes? It can also be regarded as taking care of the eyes (to avoid aesthetic fatigue);

exhibit

Without further ado, first-hand renderings

accomplish

Haha, after looking at the display picture above, do you want to show your QR code quickly? Hurry up and operate it, it is very simple to implement!

Environmental Requirements:

python3

Dependency package:

pip install amzqr

Project Git address

ide use

For simple play, you only need to modify the parameters I remarked below. If you want to see the functions of all parameters, please see github.com/x-hw/amazin…

import os
from amzqr import amzqr


if __name__ == '__main__':
    words = "https://juejin.cn/pins"

    version, level, qr_name = amzqr.run(
        words=words,  # 二维码的内容
        version=1,
        level='H',
        picture="./zombie.png",  # 需要镶入二维码的图片
        colorized=False,  # 是否上色 False(黑白) True(彩色)
        contrast=1.0,
        brightness=1.0,
        save_name="zombie_qr.png",  # 图片保存文件名
        save_dir=os.getcwd()  # 图片保存路径
    )

command line usage

# summary
amzqr Words
      [-v {1,2,3,...,40}]
      [-l {L,M,Q,H}]
      [-n output-filename]
      [-d output-directory]
      [-p picture_file]
      [-c]
      [-con contrast]
      [-bri brightness]

pay attention

Since this package does not support Chinese, if you want to generate a QR code with Chinese content, you need to make a little modification

  1. Add the following function, pass it in wordsas a parameter and turn it around
def utf16to8(input_txt: str) -> str:
    out = []
    for idx in range(len(input_txt)):
        ch = ord(input_txt[idx])
        if 0x0001 <= ch <= 0x007f:
            out.append(input_txt[idx])
        elif ch > 0x07ff:
            out.append(chr(0xE0 | (ch >> 12 & 0x0F)))
            out.append(chr(0x80 | (ch >> 6 & 0x3F)))
            out.append(chr(0x80 | (ch >> 0 & 0x3F)))
        else:
            out.append(chr(0xC0 | (ch >> 6) & 0x1f))
            out.append(chr(0x80 | (ch >> 0) & 0x3f))

    return ''.join(out)
    
words = utf16to8("每当我看见花瓣脱离花蕊慢慢枯萎")
  1. Use ide to enter runthe source code of the method and comment out the method of judging supported characters

  1. Done!

Principle thinking

If you want to implement it, you need to understand the principle of QR code generation, and then use the algorithm to find the area that is not covered by the content, and then replace the pixels of the picture;

If you are interested, you can take a look at this implementation research.swtch.com/qr/draw/ ; it can display all the controllable pixels in the QR code image, as well as random/jitter/only display the pixel area occupied by the data, very Awesome!

at last

Looking forward to the wonderful performances of your friends, I hope you can leave your fancy QR code in the comment area!

I am participating in the "Creative Development Contest" for details, please see: The Nuggets Creative Development Contest is here!

Guess you like

Origin juejin.im/post/7121982315688886308