Either ubiquitous 1D barcodes (procudct labels, ISBN in form of EAN-13 etc.) or 2D barcodes (QR containing hyperlinks, vCards etc.) encode numbers, texts or other data into images that can be printed and scanned or photographed later. Since v0.18, Relational pipes can interact with this technology.
The relpipe-in-barcode
tool reads image data from the standard input, so we can feed a file containing a barcode into it or we can generate one on-the-fly.
We can also use tee
command to store generated image data in a file.
echo -n "Big Fun" | qrencode -o - | tee qr.png | relpipe-in-barcode | relpipe-out-tabular
This pipeline generates this relation:
symbol:
╭──────────────┬───────────────┬────────────────┬─────────────┬─────────────┬─────────────────┬──────────────────╮
│ id (integer) │ type (string) │ value (string) │ x (integer) │ y (integer) │ width (integer) │ height (integer) │
├──────────────┼───────────────┼────────────────┼─────────────┼─────────────┼─────────────────┼──────────────────┤
│ 0 │ QR-Code │ Big Fun │ 12 │ 12 │ 63 │ 63 │
╰──────────────┴───────────────┴────────────────┴─────────────┴─────────────┴─────────────────┴──────────────────╯
Record count: 1
There might be multiple barcodes (symbols) in the image file and we obtain also their sizes and positions. We may read a photo:
cat barcode-qr-IMG_5758.jpeg | relpipe-in-barcode | relpipe-out-tabular
and get plenty of symbols:
symbol:
╭──────────────┬───────────────┬─────────────────────────────────────────────────────┬─────────────┬─────────────┬─────────────────┬──────────────────╮
│ id (integer) │ type (string) │ value (string) │ x (integer) │ y (integer) │ width (integer) │ height (integer) │
├──────────────┼───────────────┼─────────────────────────────────────────────────────┼─────────────┼─────────────┼─────────────────┼──────────────────┤
│ 0 │ QR-Code │ Every day, once a day, give yourself a present. │ 2100 │ 791 │ 411 │ 410 │
│ 1 │ QR-Code │ Does Barry Manilow know that you raid his wardrobe? │ 2844 │ 859 │ 375 │ 369 │
│ 2 │ QR-Code │ I'm in love. – That could be a problem. │ 2384 │ 2354 │ 320 │ 313 │
│ 3 │ QR-Code │ Grow up Heather, bulimia is so '87. │ 1625 │ 1003 │ 366 │ 365 │
│ 4 │ QR-Code │ Trust no 1. │ 4560 │ 917 │ 401 │ 384 │
│ 5 │ QR-Code │ Damn good coffee. │ 3738 │ 1775 │ 358 │ 348 │
│ 6 │ QR-Code │ Did you say a cherry or Coke slushie? │ 2946 │ 1784 │ 309 │ 310 │
│ 7 │ QR-Code │ The truth is out there. │ 4271 │ 285 │ 314 │ 301 │
│ 8 │ EAN-13 │ 9781593272203 │ 4254 │ 711 │ 138 │ 390 │
│ 9 │ EAN-13 │ 9788025712979 │ 2110 │ 1691 │ 481 │ 194 │
│ 10 │ EAN-13 │ 9788074329579 │ 2134 │ 1285 │ 314 │ 231 │
╰──────────────┴───────────────┴─────────────────────────────────────────────────────┴─────────────┴─────────────┴─────────────────┴──────────────────╯
Record count: 11
There is also (a bit experimental) example of barcode streamlet that is called from relpipe-in-filesystem
and works with several files at once (can even run in parallel, like any other streamlet):
find -print0 | relpipe-in-filesystem --parallel 8 --file name --streamlet barcode-reader | …
When we are generating QR codes and use Unicode characters (e.g. the →
arrow):
echo -n "extreme→impression" | qrencode -o - | relpipe-in-barcode | relpipe-out-csv
we may get unexpected result:
"id","type","value","x","y","width","height"
"0","QR-Code","extreme竊段mpression","12","12","74","74"
QR codes use the ISO 8859-1 encoding as default and readers usually do some heuristics to guess actual encoding.
Sometimes it works, sometimes not.
In this particular case, the reader accidentally thought that the encoding was SJIS.
So we can fix it by adding | iconv -t SJIS
at the end of the pipeline.
But this is just a workaround. We rather want to add UTF-8 BOM or ECI (Extended Channel Interpretations) to make the reader use the same encoding as we did (UTF-8):
echo -ne "\xEF\xBB\xBFextreme→impression" | qrencode -o - | relpipe-in-barcode | relpipe-out-csv
and get desired result:
"id","type","value","x","y","width","height"
"0","QR-Code","extreme→impression","12","12","74","74"
Because the relpipe-in-barcode
tool and the barcode-reader
streamlet produce data in machine readable form,
we can use them not only for manual ah-hoc reading but also in scripts or batch processing –
e.g. extract payment information from invoices or contact information from scanned business cards, catalogize books or read package labels.
Relational pipes, open standard and free software © 2018-2022 GlobalCode