You must be using QR Code, but do you know the history behind it and how to create it(using Python)?

Utkarsh Shukla
4 min readJan 26, 2023

--

History of QR Code

QR Code stands for Quick Response Code, we can say that is an upgraded version of a Bar Code, which is a 2-D barcode. The issue with the Bar Code was, it can only have up to 20 characters and need to be scanned horizontally. Industries require a bar code to store more information and to scan quickly, but this was not possible through the bar code.

This is when the QR code came into the picture. QR Code was first invented in Japan in 1994 by Toyota subsidiary Denso Wave for use in automotive manufacturing, but have since become a popular tool for a variety of applications.

Features of QR Code

One of the main advantages of QR codes is their ability to store much more information than traditional barcodes. A traditional barcode can only store a few dozen characters, while a QR code can store several hundred. This makes them ideal for storing things like URLs, contact information, and even entire documents.

Another advantage of QR codes is their ease of use. All someone needs to scan a QR code is a smartphone with a camera and a QR code reader app, which can easily be downloaded for free. Once scanned, the information stored in the QR code is immediately accessible.

QR codes are also highly customizable. They can be easily generated using a variety of online tools and can be customized with different colors, logos, and images. This makes them ideal for branding and marketing purposes.

QR codes are used in a wide range of industries, including retail, healthcare, transportation, and more. For example, in the retail industry, QR codes can be used for mobile payments, customer loyalty programs, and even inventory tracking. In the healthcare industry, QR codes can be used for patient tracking and medical records. And in the transportation industry, QR codes can be used for ticketing and baggage tracking.

Drawbacks with QR Code

However, it’s important to note that QR codes are not without their drawbacks. One major concern is security, as QR codes can be easily replicated and used for fraudulent purposes. To mitigate this risk, companies can use secure QR code generators and implement measures like encryption and authentication.

Conclusion

Overall, QR codes are a versatile and convenient tool that can be used for a variety of purposes. From retail and healthcare to transportation and marketing, QR codes are helping to make our lives more efficient and convenient. As long as security measures are in place, QR codes can be a valuable tool for any organization looking to streamline operations and improve customer engagement. There are many websites available where you can generate a QR Code for free but I am a programmer I will show you how to do it using python!

Generating QR Code using Python

We will be using the python qrcode library so make sure you have it installed also we will be generating the image, so the image library will also be used, you can run the below command to make sure you have both-

pip install qrcode

pip install pillow

We will be generating a QR code for the website nerdybio

import qrcode

# Create QR code object
qr = qrcode.QRCode(
version=1,
box_size=10,
border=5
)

# Add data to the QR code object
qr.add_data("https://www.nerdybio.com")
qr.make(fit=True)

# Create an image from the QR code object
img = qr.make_image(fill_color="black", back_color="white")

# Save the image to your computer
img.save("nerdybio_qr.png")

Run this code and it will generate the QR code for you, file will be saved in your current directory folder.

Let’s see what the output look like-

You can open up your camera, and scan this to see if it working or not, for me, it worked, doesn’t believe me? See the below screenshot!

Now, what if I want to add nerdybio logo to it?

Add logo and color to the QR Code

import qrcode
from PIL import Image

# Create QR code object
qr = qrcode.QRCode(
version=1,
box_size=10,
border=5
)

# Add data to the QR code object
qr.add_data("https://www.nerdybio.com")
qr.make(fit=True)

# Create an image from the QR code object
img = qr.make_image(fill_color="white", back_color="black")

# Open logo image
logo = Image.open("logo.png")

# Change the mode of logo to RGB
logo = logo.convert("RGB")

# Resize logo to appropriate size
logo = logo.resize((50, 50))

# Position logo in the center of QR code
img_w, img_h = img.size
logo_w, logo_h = logo.size
img.paste(logo, ((img_w - logo_w) // 2, (img_h - logo_h) // 2))

# Save the image to your computer
img.save("nerdybio_qr_logo.png")

And here it is, you can also pass hex code, in the fill color the only change you need to make is-

# Create an image from the QR code object
fill_color = hex_to_rgb("#000000")
img = qr.make_image(fill_color=fill_color, back_color="white")

Awesome isn’t it?

Github link to the above code-https://github.com/Utkarsh731/qrcode_python

Conclusion

That’s it from this blog, I think we have covered most of the things, also add this code to my [GitHub](https://github.com/Utkarsh731/qrcode_python) so that you can access it from there as well. Thanks for reading!

Still Curious? Visit to know more -Utkarsh Shukla Website

--

--

Utkarsh Shukla

Host at Professionals Unplugged | Senior Software Engineering Consultant | AWS Certified Cloud Practitioner | Transforming Ideas into Impactful Web Applications