Animated QR code Generator with Python and segno

The QR Code will generate based on some text or other type of input and it will have a cool animated background.

Animated QR code Generator with Python and segno

Table of Contents

  1. Context
  2. Pre-requisite
  3. Modules you need to install
  4. Start coding
  5. Output
  6. Reference

Context

QR code contains data in a machine readable form. You can represent almost any form of data into a QR code for example : text , contact information , urls , image , sms , number , gif , pdf , wifi joining info etc.

But the black and white QR code is a little bit boring. We can always custom our QR code in Python easily. Adding an animation on it would be really fun and an out of the box concept.


Pre-requisite

  1. Python installed.
  2. Knowledge on how to work with command prompt.
  3. A gif file to work with (just download it from google).

Modules you need to install

  • Install segno :
    I am guessing you have already installed python. So in this step we need to install segno in our environment . Run the below command on your command prompt.

To install segno from PyPi :

 $  pip install segno

OR

from conda-forge

$ conda install -c conda-forge segno
  • Install qrcode-artistic plug-in:
    We will use this plugin to create animated QR codes. You can also use this plugin to create a static QR code with a background image.

To use the plug-in ,run in your promt

 $ pip install qrcode-artistic
  • Install Pillow (PIL):
    PIL is a python imaging library and segno plugin converts the QR code into PIL image or into a QR code with image background.
 $ pip install pillow

Start coding

  • Input

    Input Text To convert in QR Code : Codengocool
    Input GIF To add in QR Code : pubg.gif This is the gif with which I want to generate my QR code. This file will go as input file.

  • Code

    First open your python command prompt from your address bar where you have stored your input file. Add the below lines :

    import segno
    qr_code=segno.make("Codengocool",error="h")
    qr_code.to_artistic(background="pubg.gif",target="pubg1.gif",scale=8)
    

    segno.make() file takes the input text or url or any other input to genrate that into a QR The name of my input file is pubg. So background="your_file_name.gif" and target="out_file_name.gif". And scale="the output image's bit depth"


Output

After executing the third line of code , the output file will generate. Here is the one that the above code generated:

pubg1.gif


Reference

  1. segno
  2. Gif taken from this link
  3. qr-artistic
  4. Artistic QR Code