Live stream set for 2025-04-13 at 14:00:00 Eastern
Ask questions in the live chat about any programming or lifestyle topic.
This livestream will be on Odysee or you can watch below.
Creating And Reading Barcodes
A barcode is a method of representing machine-readable images consisting of black and white bars.
Multiple tools are available for generating barcodes. Some are command-line only, while others have a GUI.
In a 1D barcode, data is scanned in a linear sequence using a series of vertical lines and spaces of varying widths to encode data.
There are many different types of 2D barcodes such as QR code and Aztec code. QR codes are matrix barcodes that can contain alphanumeric and binary data. A popular use of QR codes is to share a link to a website for people with mobile devices.
In this tutorial, the Libqrencode library will be used to encode data in a QR code. The test will consist of encoding simple text, then URLs and finally an address book entry in vCard format.
Requirements For Barcode Generator
Glossary:
GUI
Graphical User Interface allows users to interact with electronic devices through graphic icons and indicators.
1D
One-dimensional or linear.
2D
Two-dimensional developed, using geometric patterns like rectangles, dots, and hexagons.
Data Matrix
Two-dimensional barcode with uniquely generated patterns of square modules.
vCard
Virtual Contact File (VCF) is a file format standard for electronic business cards.
Common Barcodes
Name | Description | Example |
---|---|---|
1D Barcode | Scanned horizontally and can hold 85 characters. | Universal Product Code (UPC). |
2D Barcode | Scanned horizontally and vertically and can hold 7089 characters. | QR Code. |
Name | Description | Example |
Generate QR Codes Via Libqrencode
# Create Text Link In QR Code # qrencode -o qrcode1.png 'https://ojambo.com' # Create Text Link With Increased Border Width Pixels In QR Code # qrencode -m 10 -o qrcode2.png 'https://ojambo.com' # Create Text Link With Increased Border Width And Height Pixels In QR Code # qrencode -s 4 -m 10 -o qrcode3.png 'https://ojambo.com' # Create Text Address Book Entry In QR Code # cat > vcard.vcf << 'EOF' BEGIN:VCARD VERSION:3.0 FN:Edward Ojambo N:Ojambo;Edward;;; EMAIL;type=HOME,INTERNET:edward@ojamboshow.local URL:https://ojambo.com END:VCARD EOF cat vcard.vcf | qrencode -o address.png
Download
The Libqrencode library can be downloaded from Libqrencode Library and installed on your workstation.
Explanation
- Generate a file with your QR code.
- Test the QR Code on your scanning device such as a smartphone.
- Optionally tweak the width and height of the border in pixels.
- In order to generate a VCF-encoded QR code, place the contents in a separate file (literal VCF).
- The library accepts a string or a list of data chunks.



Usage
You can use the Libqrencode command line tool to generate QR codes using the default settings. For this tutorial, QR codes were generated for plain text, URL and vCard. You can use generated QR codes for even ticketing and product information among other uses.
Open Source
Libqrencode is licensed under the terms of the GNU Lesser General Public License (LGPL) version 2.1. The copyleft license comes with strict rules and requirements to ensure the software remains free and open-source. It allows commercial use, modification, distribution, and allows making derivatives proprietary, consult the license for more specific details.
Conclusion:
Libqrencode can be used to generate QR codes on your local computer without restrictions. You can generated encoded text, URL, VCF and more on the command line. You are able to tweak the height and border pixels.
If you enjoy this article, consider supporting me by purchasing one of my OjamboShop.com Online Programming Courses or publications at Edward Ojambo Programming Books or simply donate here Ojambo.com Donate
References:
- Libqrencode QR Code Encoding Library
- Customer Sets Price Plugin for WooCommerce on Ojambo.com
- Learning JavaScript Course on OjamboShop.com
- Learning Python Course on OjamboShop.com
- Learning PHP Course on OjamboShop.com
- Learning JavaScript Paperback on Amazon
- Learning JavaScript Ebook on Amazon
- Learning Python Ebook on Amazon
- Learning PHP Ebook on Amazon
- OjamboServices.com For Custom Websites, Applications & Tutorials