DEV Community

Cover image for Bulk converts files to QR codes
petercour
petercour

Posted on

2 1

Bulk converts files to QR codes

What's the craziest way to take backups? The cloud? floppy disks? QR codes?

QR codes started with the Japanese automobile industry. They are graphical codes you can use to store data.

You can quack QR codes with duckduckgo. Type "QR hello world" for it to generate a QR code containing "hello world". But did you know you can do it from code?

QR codes backup with Python

We'll convert files in bulk to QR codes with Python programming. This guide is for Linux computers.

Install zbar-tools and qrcode module

sudo apt install zbar-tools
Enter fullscreen mode Exit fullscreen mode

Then you can convert all (.py) files in a directory to qr codes.

#!/usr/bin/python3
import qrcode
import glob

files = glob.glob("*.py")
for filename in files:
    data = ""
    with open(filename, 'r') as file:
            data = file.read()

    img = qrcode.make(data)
    img.save('qr-' + filename + '.png')
Enter fullscreen mode Exit fullscreen mode

There's a limit to the file size, about 8 kilobytes. But for small files this actually works.

This creates a QR code when running the program for each python file in the directory (*.py).

You can decode a QR code with the command:

zbarimg qr-qrfs.py.png
Enter fullscreen mode Exit fullscreen mode

Then you can print all your files on paper. If they files fit into the QR code that is.

Related links:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay