Surely every college student has a gentle and lovely little sister. A lot of people have admired young girls for a long time, but they just don’t know how to soak them. Today, bloggers give you tips.

I’ll give you a TWO-DIMENSIONAL code today.

First effect:

Insert a picture description here

This is what comes straight out of it



If you change the middle picture to the fairy picture of the younger sister, and the text part to the affectionate confession, it will not take a minute to succeed.

QRCode is a relatively useful Python package dedicated to manipulating QR codes. PIP install qrcode PIP install qrcode

Step 2 Install PIL package Because you need to operate on the image, so you need this PIL package for image operation. It may be a bit troublesome to follow PIL, so you need to download it from the official website and then decompress it.

The third step is to generate the TWO-DIMENSIONAL code

qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=2.)# add data
    qr.add_data(strs)
    # fill data
    qr.make(fit=True)
    # generate images
    img = qr.make_image(fill_color="pink", back_color="white")
Copy the code

There are more detailed comments in the code, here is a small trick. The blogger changed the default color of the QR code from black to pink. The old man’s girl heart is full, of course you can also change the color that the younger sister likes.

Step 4 Copy the logo picture to the QR code

	# add logo
    icon = Image.open("01.jpg")
    Get the width and height of the image
    img_w, img_h = img.size
	img.paste(icon, (w, h), icon)
    img.show()
Copy the code

… Complete code, please move to the public number: poetic code

How to get rid of the black and white box programming, learn to do a plane fight in c++ in 1 hour