Wednesday, July 6, 2022

Zint Barcode Generator

Zint is a cross-platform open source barcode generating library which can be found at

https://www.zint.org.uk/.

You can get zint from the following github repository.

https://github.com/woo-j/zint.



Zint Setup on Linux

Once you clone the github repository, you follow these steps to setup zint.
$ sudo apt install -y git cmake libpng-dev
$ git clone https://github.com/woo-j/zint.git 
$ cd zint/ 
$ mkdir build 
$ cd build 
$ cmake .. 
$ make 
$ sudo make install 
$ sudo sh -c "echo /usr/local/lib/ > /etc/ld.so.conf.d/zint.conf"
$ sudo ldconfig 

Thereafter, you can should see zint binary application in /usr/local/bin folder. To test zint, you can use the following command to generate a barcode image.
$ zint -o bar01.png -b 1 --height=50 --border=10 -d 87654321

More example commands can be found in "test.sh" script file which is in zint repository under frontend sub-directory.

Simple C Example

A simple C program (simple.c) using zint library is shown below. Please refer to line 899 of its manual for more details [1].
#include < stdio.h >
#include < zint.h >
int main()
{
	struct zint_symbol *my_symbol;
	my_symbol = ZBarcode_Create();
	if(my_symbol != NULL){
		printf("Symbol successfully created!\n");
	}
	ZBarcode_Encode(my_symbol, "87654321",0);
	ZBarcode_Print(my_symbol,0);
	ZBarcode_Delete(my_symbol);
	return 0;
}

You can build and run the program as follows.
$ gcc -o zintsimple zintsimple.c -lzint
$ ./zintsimple

Manipulating Zint Image

As an another example, we will use zint to generate barcode, use its bitmap values directly in the program to process with OpenCV, and show as a GUI image using wxWidgets functions discussed at [2]. The program can be found at the following link.
https://github.com/yan9a/rpi/blob/master/opencv/barcode/zintimg/zintimg.cpp

References

[1] Zint. Manual.
url: https://github.com/woo-j/zint/blob/master/docs/manual.txt.

[2] Cool Emerald. OpenCV with wxWidgets. 2017 Nov 23.
url: http://cool-emerald.blogspot.com/2017/11/opencv-with-wxwidgets.html.



No comments:

Post a Comment

Comments are moderated and don't be surprised if your comment does not appear promptly.