<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://ps.wdka.nl/wiki/index.php?action=history&amp;feed=atom&amp;title=Barcode</id>
	<title>Barcode - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ps.wdka.nl/wiki/index.php?action=history&amp;feed=atom&amp;title=Barcode"/>
	<link rel="alternate" type="text/html" href="https://ps.wdka.nl/wiki/index.php?title=Barcode&amp;action=history"/>
	<updated>2026-06-01T14:47:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://ps.wdka.nl/wiki/index.php?title=Barcode&amp;diff=3438&amp;oldid=prev</id>
		<title>Andre: Created page with &quot; Barcodes are essential encoding of characters onto black bars of different width and blanks.  There are there several types of barcodes, we&#039;ll look into:  ==Code 128== More i...&quot;</title>
		<link rel="alternate" type="text/html" href="https://ps.wdka.nl/wiki/index.php?title=Barcode&amp;diff=3438&amp;oldid=prev"/>
		<updated>2016-05-31T10:22:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; Barcodes are essential encoding of characters onto black bars of different width and blanks.  There are there several types of barcodes, we&amp;#039;ll look into:  ==Code 128== More i...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
Barcodes are essential encoding of characters onto black bars of different width and blanks.&lt;br /&gt;
&lt;br /&gt;
There are there several types of barcodes, we&amp;#039;ll look into:&lt;br /&gt;
&lt;br /&gt;
==Code 128==&lt;br /&gt;
More info barcode code 128 encoding in:&lt;br /&gt;
* http://grandzebu.net/informatique/codbar-en/code128.htm&lt;br /&gt;
* http://en.wikipedia.org/wiki/Code_128&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import Image&lt;br /&gt;
import ImageDraw&lt;br /&gt;
&lt;br /&gt;
# Info barcode code 128 encoding in http://grandzebu.net/informatique/codbar-en/code128.htm&lt;br /&gt;
# Copied from http://en.wikipedia.org/wiki/Code_128&lt;br /&gt;
# Value Weights 128A    128B    128C&lt;br /&gt;
CODE128_CHART = &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
0       212222  space   space   00&lt;br /&gt;
1       222122  !       !       01&lt;br /&gt;
2       222221  &amp;quot;       &amp;quot;       02&lt;br /&gt;
3       121223  #       #       03&lt;br /&gt;
4       121322  $       $       04&lt;br /&gt;
5       131222  %       %       05&lt;br /&gt;
6       122213  &amp;amp;       &amp;amp;       06&lt;br /&gt;
7       122312  &amp;#039;       &amp;#039;       07&lt;br /&gt;
8       132212  (       (       08&lt;br /&gt;
9       221213  )       )       09&lt;br /&gt;
10      221312  *       *       10&lt;br /&gt;
11      231212  +       +       11&lt;br /&gt;
12      112232  ,       ,       12&lt;br /&gt;
13      122132  -       -       13&lt;br /&gt;
14      122231  .       .       14&lt;br /&gt;
15      113222  /       /       15&lt;br /&gt;
16      123122  0       0       16&lt;br /&gt;
17      123221  1       1       17&lt;br /&gt;
18      223211  2       2       18&lt;br /&gt;
19      221132  3       3       19&lt;br /&gt;
20      221231  4       4       20&lt;br /&gt;
21      213212  5       5       21&lt;br /&gt;
22      223112  6       6       22&lt;br /&gt;
23      312131  7       7       23&lt;br /&gt;
24      311222  8       8       24&lt;br /&gt;
25      321122  9       9       25&lt;br /&gt;
26      321221  :       :       26&lt;br /&gt;
27      312212  ;       ;       27&lt;br /&gt;
28      322112  &amp;lt;       &amp;lt;       28&lt;br /&gt;
29      322211  =       =       29&lt;br /&gt;
30      212123  &amp;gt;       &amp;gt;       30&lt;br /&gt;
31      212321  ?       ?       31&lt;br /&gt;
32      232121  @       @       32&lt;br /&gt;
33      111323  A       A       33&lt;br /&gt;
34      131123  B       B       34&lt;br /&gt;
35      131321  C       C       35&lt;br /&gt;
36      112313  D       D       36&lt;br /&gt;
37      132113  E       E       37&lt;br /&gt;
38      132311  F       F       38&lt;br /&gt;
39      211313  G       G       39&lt;br /&gt;
40      231113  H       H       40&lt;br /&gt;
41      231311  I       I       41&lt;br /&gt;
42      112133  J       J       42&lt;br /&gt;
43      112331  K       K       43&lt;br /&gt;
44      132131  L       L       44&lt;br /&gt;
45      113123  M       M       45&lt;br /&gt;
46      113321  N       N       46&lt;br /&gt;
47      133121  O       O       47&lt;br /&gt;
48      313121  P       P       48&lt;br /&gt;
49      211331  Q       Q       49&lt;br /&gt;
50      231131  R       R       50&lt;br /&gt;
51      213113  S       S       51&lt;br /&gt;
52      213311  T       T       52&lt;br /&gt;
53      213131  U       U       53&lt;br /&gt;
54      311123  V       V       54&lt;br /&gt;
55      311321  W       W       55&lt;br /&gt;
56      331121  X       X       56&lt;br /&gt;
57      312113  Y       Y       57&lt;br /&gt;
58      312311  Z       Z       58&lt;br /&gt;
59      332111  [       [       59&lt;br /&gt;
60      314111  \       \       60&lt;br /&gt;
61      221411  ]       ]       61&lt;br /&gt;
62      431111  ^       ^       62&lt;br /&gt;
63      111224  _       _       63&lt;br /&gt;
64      111422  NUL     `       64&lt;br /&gt;
65      121124  SOH     a       65&lt;br /&gt;
66      121421  STX     b       66&lt;br /&gt;
67      141122  ETX     c       67&lt;br /&gt;
68      141221  EOT     d       68&lt;br /&gt;
69      112214  ENQ     e       69&lt;br /&gt;
70      112412  ACK     f       70&lt;br /&gt;
71      122114  BEL     g       71&lt;br /&gt;
72      122411  BS      h       72&lt;br /&gt;
73      142112  HT      i       73&lt;br /&gt;
74      142211  LF      j       74&lt;br /&gt;
75      241211  VT      k       75&lt;br /&gt;
76      221114  FF      l       76&lt;br /&gt;
77      413111  CR      m       77&lt;br /&gt;
78      241112  SO      n       78&lt;br /&gt;
79      134111  SI      o       79&lt;br /&gt;
80      111242  DLE     p       80&lt;br /&gt;
81      121142  DC1     q       81&lt;br /&gt;
82      121241  DC2     r       82&lt;br /&gt;
83      114212  DC3     s       83&lt;br /&gt;
84      124112  DC4     t       84&lt;br /&gt;
85      124211  NAK     u       85&lt;br /&gt;
86      411212  SYN     v       86&lt;br /&gt;
87      421112  ETB     w       87&lt;br /&gt;
88      421211  CAN     x       88&lt;br /&gt;
89      212141  EM      y       89&lt;br /&gt;
90      214121  SUB     z       90&lt;br /&gt;
91      412121  ESC     {       91&lt;br /&gt;
92      111143  FS      |       92&lt;br /&gt;
93      111341  GS      }       93&lt;br /&gt;
94      131141  RS      ~       94&lt;br /&gt;
95      114113  US      DEL     95&lt;br /&gt;
96      114311  FNC3    FNC3    96&lt;br /&gt;
97      411113  FNC2    FNC2    97&lt;br /&gt;
98      411311  ShiftB  ShiftA  98&lt;br /&gt;
99      113141  CodeC   CodeC   99&lt;br /&gt;
100     114131  CodeB   FNC4    CodeB&lt;br /&gt;
101     311141  FNC4    CodeA   CodeA&lt;br /&gt;
102     411131  FNC1    FNC1    FNC1&lt;br /&gt;
103     211412  StartA  StartA  StartA&lt;br /&gt;
104     211214  StartB  StartB  StartB&lt;br /&gt;
105     211232  StartC  StartC  StartC&lt;br /&gt;
106     2331112 Stop    Stop    Stop&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;.split()&lt;br /&gt;
&lt;br /&gt;
VALUES   = [int(value) for value in CODE128_CHART[0::5]]&lt;br /&gt;
WEIGHTS  = dict(zip(VALUES, CODE128_CHART[1::5]))&lt;br /&gt;
CODE128A = dict(zip(CODE128_CHART[2::5], VALUES))&lt;br /&gt;
CODE128B = dict(zip(CODE128_CHART[3::5], VALUES))&lt;br /&gt;
CODE128C = dict(zip(CODE128_CHART[4::5], VALUES))&lt;br /&gt;
&lt;br /&gt;
for charset in (CODE128A, CODE128B):&lt;br /&gt;
    charset[&amp;#039; &amp;#039;] = charset.pop(&amp;#039;space&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def code128_format(data):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Generate an optimal barcode from ASCII text&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    text     = str(data)&lt;br /&gt;
    pos      = 0&lt;br /&gt;
    length   = len(text)&lt;br /&gt;
    &lt;br /&gt;
    # Start Code&lt;br /&gt;
    if text[:2].isdigit() and length &amp;gt; 1:&lt;br /&gt;
        charset = CODE128C&lt;br /&gt;
        codes   = [charset[&amp;#039;StartC&amp;#039;]]&lt;br /&gt;
    else:&lt;br /&gt;
        charset = CODE128B&lt;br /&gt;
        codes   = [charset[&amp;#039;StartB&amp;#039;]]&lt;br /&gt;
    &lt;br /&gt;
    # Data&lt;br /&gt;
    while pos &amp;lt; length:&lt;br /&gt;
        if charset is CODE128C:&lt;br /&gt;
            if text[pos:pos+2].isdigit() and length - pos &amp;gt; 1:&lt;br /&gt;
                # Encode Code C two characters at a time&lt;br /&gt;
                codes.append(int(text[pos:pos+2]))&lt;br /&gt;
                pos += 2&lt;br /&gt;
            else:&lt;br /&gt;
                # Switch to Code B&lt;br /&gt;
                codes.append(charset[&amp;#039;CodeB&amp;#039;])&lt;br /&gt;
                charset = CODE128B&lt;br /&gt;
        elif text[pos:pos+4].isdigit() and length - pos &amp;gt;= 4:&lt;br /&gt;
            # Switch to Code C&lt;br /&gt;
            codes.append(charset[&amp;#039;CodeC&amp;#039;])&lt;br /&gt;
            charset = CODE128C&lt;br /&gt;
        else:&lt;br /&gt;
            # Encode Code B one character at a time&lt;br /&gt;
            codes.append(charset[text[pos]])&lt;br /&gt;
            pos += 1&lt;br /&gt;
    &lt;br /&gt;
    # Checksum&lt;br /&gt;
    checksum = 0&lt;br /&gt;
    for weight, code in enumerate(codes):&lt;br /&gt;
        checksum += max(weight, 1) * code&lt;br /&gt;
    codes.append(checksum % 103)&lt;br /&gt;
    &lt;br /&gt;
    # Stop Code&lt;br /&gt;
    codes.append(charset[&amp;#039;Stop&amp;#039;])&lt;br /&gt;
    return codes&lt;br /&gt;
&lt;br /&gt;
def code128_image(data, height=100, thickness=3, quiet_zone=True):&lt;br /&gt;
    if not data[-1] == CODE128B[&amp;#039;Stop&amp;#039;]:&lt;br /&gt;
        data = code128_format(data)&lt;br /&gt;
    &lt;br /&gt;
    barcode_widths = []&lt;br /&gt;
    for code in data:&lt;br /&gt;
        for weight in WEIGHTS[code]:&lt;br /&gt;
            barcode_widths.append(int(weight) * thickness)&lt;br /&gt;
    width = sum(barcode_widths)&lt;br /&gt;
    x = 0&lt;br /&gt;
&lt;br /&gt;
    if quiet_zone:&lt;br /&gt;
        width += 20 * thickness&lt;br /&gt;
        x = 10 * thickness&lt;br /&gt;
&lt;br /&gt;
    # Monochrome Image&lt;br /&gt;
    img  = Image.new(&amp;#039;1&amp;#039;, (width, height), 1)&lt;br /&gt;
    draw = ImageDraw.Draw(img)&lt;br /&gt;
    draw_bar = True&lt;br /&gt;
    for width in barcode_widths:&lt;br /&gt;
        if draw_bar:&lt;br /&gt;
            draw.rectangle(((x, 0), (x + width - 1, height)), fill=0)&lt;br /&gt;
        draw_bar = not draw_bar&lt;br /&gt;
        x += width&lt;br /&gt;
&lt;br /&gt;
    return img&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Research]]&lt;/div&gt;</summary>
		<author><name>Andre</name></author>
	</entry>
</feed>