BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

Post your working scripts, libraries and tools
newbieforever
Posts: 447
Joined: 24 Aug 2016, 03:34

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

29 Nov 2018, 15:44

PS:
I use now Zint to generate my codes.
But...to resume my original question:
Is there really no approach or attempt of a solution in AHK to generate datamatrix codes?
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

30 Nov 2018, 08:53

Is there really no approach or attempt of a solution in AHK to generate datamatrix codes?
I have taken a look into the DataMatrix standards before and they seem to be very similar to QR Codes in many technical aspects (use of reed solomon error correction, use of finder patterns, disposing the bits in specific ways, etc). If my experience in developing the QR Code generator function is to be accounted for, i would say it would take around a month to develop a complete DataMatrix generator fully coded in AutoHotkey from scratch. A simpler version, such as fixed length, fixed ECL, ASCII only, etc, should probably be doable in a few days though. Having the QR Code generator as a guide should decrease the development time a little too.

As mentioned, i currently have no plans of doing this as i am particularly focused into some other projects. But what size are the data strings that you are trying to encode? It is ASCII data? Does a fixed version suffices or do you absolutely need the smallest possible matrix? Does it have to be GS1 compatible? If you are willing to develop it yourself, i may be able to help with the most confusing parts (i.e.: implementing the Reed-Solomon error correction, etc) provided that you are willing to share the code with the community afterwards, of course.
wodzu
Posts: 7
Joined: 06 Dec 2018, 02:21

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

06 Dec 2018, 02:32

First of all, I would like to thank you @Gio for this awesome script you made - brilliant job!

I am using this part of your code that generates a 128 barcode. It works very good for my purpose but I need to make it bigger somehow. I'm printing this barcode on a Zebra printer and the quality is not good enough. I tryed to change the bitmap resolution but this don't seem to work. Could you help me here, please?

Here's the part of the code I'm using:

Code: Select all

MATRIX_TO_PRINT := BARCODER_GENERATE_CODE_128B(KodOdbioru)
if (MATRIX_TO_PRINT = 1)
{
Msgbox, 0x10, Error, The input message is either blank or contains characters that cannot be encoded in CODE_128B.

}
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system

}
HEIGHT_OF_IMAGE := 20 ; 20 is the arbitrary height of the Barcode image for this example. You can chage it to any number to increase/decrease the height of the image. Since a scanner must get an accurate vision of a full line, a taller image may offer a higher chance that a physically damaged print will have at least 1 fully readable line (This should not be confused with QR Codes Error Correction Level protection though).
pBitmap := Gdip_CreateBitmap(MATRIX_TO_PRINT.MaxIndex() + 8, HEIGHT_OF_IMAGE + 25) ; Adding 8 pixels to the width here as a "quiet zone" for the image. This serves to improve the printed code readability.
Gdip_BitmapSetResolution(pBitmap,600,600)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(pBitmap, 3)
pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, MATRIX_TO_PRINT.MaxIndex() + 8, HEIGHT_OF_IMAGE + 25) ; Same as above
Gdip_DeleteBrush(pBrush)
Loop % HEIGHT_OF_IMAGE
{
CURRENT_ROW := A_Index
Loop % MATRIX_TO_PRINT.MaxIndex()
{
CURRENT_COLUMN := A_Index
If (MATRIX_TO_PRINT[A_Index] = 1)
{
Gdip_SetPixel(pBitmap, CURRENT_COLUMN + 1, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
}
}
}

CURRENT_ROW := "", CURRENT_COLUMN := ""
Options = x30 y22 cFF000000 r1 s20
Gdip_TextToGraphics(G, KodOdbioru, Options, "Arial")

StringReplace, FILE_NAME_TO_USE, KodOdbioru, `" ; We can't use all the characters that byte mode can encode in the name of the file. So we are replacing them here (if they exist).
FILE_PATH_AND_NAME := A_ScriptDir . "\input\" . SubStr(RegExReplace(FILE_NAME_TO_USE, "[\t\r\n\\\/\`:\`?\`*\`|\`>\`<]"), 1, 20) . ".png" ; Same as above. We will only use the first 20 characters for the file name in this example.
Gdip_SaveBitmapToFile(pBitmap, FILE_PATH_AND_NAME)
Gdip_DisposeImage(pBitmap)
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

06 Dec 2018, 09:05

Hello Wodzu.

Glad you found the library useful :thumbup:

The example below allows you to adjust pixel-width based on the desired numbers for the thinnest lines. Also, you can adjust image height in pixels (i suggest using 20x the base pixel-width you chose for the pixel height of the image).

Code: Select all

inputbox, PixelSize,, Type in the desired PIXEL-WIDTH for the thinnest bars.
inputbox, HEIGHT_OF_IMAGE,, Type in the desired PIXEL-HEIGHT of the image.
inputbox, MESSAGE_TO_ENCODE,, Type in the MESSAGE you wish to encode.

MATRIX_TO_PRINT := BARCODER_GENERATE_CODE_128B(MESSAGE_TO_ENCODE)
if (MATRIX_TO_PRINT = 1)
{
Msgbox, 0x10, Error, The input message is either blank or contains characters that cannot be encoded in CODE_128B.

}
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system

}
pBitmap := Gdip_CreateBitmap(((MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize) , HEIGHT_OF_IMAGE + 25) ; Adding 8 pixels to the width here as a "quiet zone" for the image. This serves to improve the printed code readability.
Gdip_BitmapSetResolution(pBitmap,600,600)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(pBitmap, 3)
pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, ((MATRIX_TO_PRINT.MaxIndex() + 8) * PixelSize), HEIGHT_OF_IMAGE + 25) ; Same as above
Gdip_DeleteBrush(pBrush)
Loop % HEIGHT_OF_IMAGE
{
CURRENT_ROW := A_Index
Loop % MATRIX_TO_PRINT.MaxIndex()
{
CURRENT_COLUMN := A_Index
If (MATRIX_TO_PRINT[A_Index] = 1)
{
	Loop % PixelSize
	{
		; Gdip_SetPixel(pBitmap, CURRENT_COLUMN + 1, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
		Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * PixelSize) + (3*PixelSize) - 1 + A_Index, CURRENT_ROW, 0xFF000000) ; Adding 3 to the current column and the current row to skip the quiet zones.
	}
}
}
}

CURRENT_ROW := "", CURRENT_COLUMN := ""
Options = x30 y22 cFF000000 r1 s20
Gdip_TextToGraphics(G, KodOdbioru, Options, "Arial")

StringReplace, FILE_NAME_TO_USE, KodOdbioru, `" ; We can't use all the characters that byte mode can encode in the name of the file. So we are replacing them here (if they exist).
FILE_PATH_AND_NAME := A_ScriptDir . "\input\" . SubStr(RegExReplace(FILE_NAME_TO_USE, "[\t\r\n\\\/\`:\`?\`*\`|\`>\`<]"), 1, 20) . ".png" ; Same as above. We will only use the first 20 characters for the file name in this example.
Gdip_SaveBitmapToFile(pBitmap, FILE_PATH_AND_NAME)
Gdip_DisposeImage(pBitmap)

This post by JoeWinograd contains an example in case you also need to adjust the dimensions for a QR Code image.
mattkingston
Posts: 18
Joined: 14 Oct 2016, 13:17

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

25 Jun 2019, 07:56

Excellent work!
Can I ask though, is it possible to increase the resolution of the generated barcode.
Id like to scale it a to a larger size without blurring the code lines.

Thanks in advance.
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

25 Jun 2019, 11:54

Yes, there are actually a few examples on how to do it in the replies to the topic already. Which type of barcode you are using?
baboo1308
Posts: 2
Joined: 20 Sep 2019, 06:49

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 06:58

We issue bar codes.
CODE39 Line 4 and QR Code Line 1 are used.
The comma[,] is not implemented during the QR code progress, but is expressed as zero.
Is there any way to generate a comma[,] when issuing QR codes?
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 09:07

Hello Baboo1308.

I tried the example 2 in the first post of this topic and was actually able to generate messages that included commas no problem.

:arrow: Besides kanji, there are 3 code modes in QR Codes:
Numeric mode allows numbers only
Alphanumeric mode allows Numbers, UPPERCASE letters A-Z and symbols ; $, %, *, +, -, ., /, :, and \.
Byte mode allows the full ASCII table.

You should use the later if you wish to write commas. If you are using the Barcoder library, it will choose the best mode based on your input message, but even if this auto-choice is not working, you can also force the function BARCODER_GENERATE_QR_CODE() to use Byte mode only by assigning value 3 as the second parameter of the function.
baboo1308
Posts: 2
Joined: 20 Sep 2019, 06:49

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

20 Sep 2019, 09:22

Hello, GIO

I did TEST now.

Barcode scanning works so well.
Thank you so much.
bourdin07
Posts: 33
Joined: 23 Jun 2019, 12:57

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

28 Feb 2020, 21:05

Best language for automation, I'll integrate to my framework

You should refactor your library to encapsulate in a class instead using global
blue83
Posts: 126
Joined: 11 Apr 2018, 06:38

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

02 Mar 2020, 14:28

Hi @Gio

can you create one code for reading barcodes from pdf files or images?
I am interested for PDF 417 format but I am sure that there is need also for the other formats.

Thanks,
Blue
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

06 Mar 2020, 10:24

Hello Blue83.

If you intend to make a barcode reader, you will have 2 options: either use an external program as an aid (ZBar is a good example) OR develop the entire image processing routine in AutoHotkey. The former option has the con of creating external dependencies, the later has the con of being a small project in and by itself (expect 20+ hours of work at the very least).

If you intend to go the easy way (using external utilities), you can either search for a decoder that directly supports PDF417 OR if decoding time is not a problem, use a file converter in-between to convert the PDF417 to PNG (or other format) for use on a decoder that supports PNG (or other format).
animagus46
Posts: 22
Joined: 19 Dec 2014, 15:23

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

28 May 2020, 02:43

hello gio, thank you for your barcode generator,
I would be interested in whether it is possible to set a text after the qrcode has been created,
on the side or below the qrcode. it would only be a short text with a maximum of 10 characters.
Like this
https://www.huebner-giessen.com/fileadmin/media/news/2019/qrcode-dummy.jpg
I am currently using GDIP.ahk to add text to the image.
Do you or someone have an idea how I can do this in the barcode generator? If I have read that correctly, there is no function for it.
Thank you very much
animagus
User avatar
Gio
Posts: 1067
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: BARCODER - Create 1D and 2D Barcodes (QRCode , C39,etc)

28 May 2020, 10:37

Hello animagus46.

BARCODER is only meant to receive a message and then to provide an easy-to-use map of how to draw the corresponding QR Code matrix. The reason being is that you can then choose whichever method best suits your application to actually draw the QR Code matrix.

GDIP_All.ahk is used in the examples to provide an idea on how to easily finish the drawing of the QR Code, and i even recommend it for most cases in AHK, but this library is not meant to actually choose the drawing method for you. The reason being is that you can have no other dependencies at all if you don't want to. As an example of other possible drawing method choices (aside of using GDIP_All.ahk to finish the drawing) you can have your code:

1. Use direct calls to gdiplus.dll (which is a windows dll).
2. Generate a bitmap file based on the file structure and binary control.
3. Use any third-party utility that allows programable drawing.
4. Code the output matrix in html/CSS/javascript for display in a web browser.
5. Output the binary information directly to a reader library and avoid actual image rendering.
6. etc, etc, etc.

:arrow: Is there any specific reason for you to be looking for an alternative to GDIP?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot] and 23 guests