Output formats
Barcodes are generated in one of five formats that may be embedded directly into an HTML document. There is no option to output a binary image file. (Okay, so there's actually one way to do this - see the Drush commands page for details). The five formats available are:
- PNG Image ('png')
This generates a
<img>tag containing an embedded, base64 encoded PNG image which will look something like:
<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAABlBMVEX///8AAABVwtN+AAAAAXRSTlMAQObYZgAAAAlwSFlzAAAOxAAADsQBlSsOGwAAACNJREFUOI1j2CiyOGO3yNLTs67NNTRgGOWN8kZ5o7xRHo15AOGSiPPiFchBAAAAAElFTkSuQmCC" /> - SVG Image ('svg')
This generates a
<svg>tag containing an embedded SVG image. This format is very verbose. You may see an example by looking at the code we use for testing this module:
https://git.drupalcode.org/project/barcodes/-/blob/2.1.x/tests/src/Functional/BarcodeBlockTest.php?ref_type=heads#L153-189 - HTML DIV ('htmldiv')
This generates
<div>tags which are explicitly sized and which use the CSSbackground-colorproperty to "draw" the barcode in HTML. This format is very verbose. You may see an example by looking at the code we use for testing this module:
https://git.drupalcode.org/project/barcodes/-/blob/2.1.x/tests/src/Functional/BarcodeBlockTest.php?ref_type=heads#L194-227 - Unicode String ('unicode')
This generates a
<pre>tag containing solid shapes represented by Unicode characters. Like the<div>output above, these shapes are used to draw the barcode on an HTML page. This will look something like:
<pre style="font-family:monospace;line-height:0.61em;font-size:6px;">▄ ▄▄ ▄ ▄ ▄ ▄ ▄ ▄▄ ▄ ▄ ▄ ▄▄ ▄▄ ▄ ▄ ▄ ▄ ▄ ▄▄ ▄ ▄▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄▄ ▄ ▄▄ ▄ ▄
</pre> - Binary String ('binary')
This generates a
<pre>tag containing ASCII characters "0" and "1" to simulate the appearance of bars ("1") and spaces between the bars ("0"). The relative widths of the bars and spaces are shown by repeating the characters. This will look something like:
<pre style="font-family:monospace;">101100100101010100110101001011011001010101010110010110010101010101001101011001001
</pre>
(All five of these example encode the same data, "023130" as a CODABAR barcode.)
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion