Code: Images, barcodes and labels with Jennifer
Images, barcodes and labels with Jennifer: the code
The programs behind the slides, for Jennifer 0.27.0. Run them from this folder; they read and write their files by relative path.
Setup:
sh make-samples.shcreates the sample pictures (holiday.jpg,phone.jpg,page.jpg,logo.svg) with ImageMagick 7. They stand in for the photos used in the talk, so sizes in the output match the slides but the pictures do not.jvc installfetches the two decks indeck.toml(@deckyard/magick,@deckyard/escl) intovendor/. Onlymagick.j,magickerr.j,scan.jandesclerr.jneed them;@deckyard/magickalso needs themagickcommand (ImageMagick 7) on the PATH.bomb.pngis a 75-byte PNG header that claims 100000 x 100000 pixels.- Optional, to read the codes back as on the slides:
zbarimg(zbar) andpdftoppm(poppler).
Images (use images;):
info.j:images.infofrom the header, decode,fitinto 320 x 320, write JPEG and PNG thumbnails ("Load, look, shrink"). Run:jennifer run info.jedit.j: crop, resize, grayscale, dither, rotate, drawn side by side intostrip.png("Crop, resize, turn, dither"). Run:jennifer run edit.jhostile.j: a decompression bomb refused with kind"limit"("Hostile pictures"). Run:jennifer run hostile.jimgerr.j: a non-image, a crop outside the image, a 45 degree turn ("Errors and limits"). Run:jennifer run imgerr.jmagick.j: identify, auto-orient, thumbnail, annotate and write WebP through@deckyard/magick("What images does not do: @deckyard/magick"). Run:jennifer run magick.jmagickerr.j: what the built-in library reports for the sideways photo, SVG refused unless allowed, the bomb through ImageMagick ("Errors and limits"). Run:jennifer run magickerr.j
Barcodes (import "barcode.j"):
qr.j: one URL as a QR code at the four error correction levels, written toqr-L.png...qr-H.png("Barcodes: one Symbol, several renderers"). Run:jennifer run qr.jdamage.j: puts a red sticker on each QR code,hit-L.png...hit-H.png("Error correction, tested with a sticker"). Run afterqr.j:jennifer run damage.j, thenfor l in L M Q H; do echo $l: $(zbarimg -q hit-$l.png || echo none); donecodes.j: Code 128, EAN-13, GS1-128 and Data Matrix as PNG and SVG ("Four more symbologies", "Scan them back", "SVG or PNG"). Run:jennifer run codes.j, thenzbarimg -q code128.png ean13.png gs1-128.pngbcerr.j: a wrong check digit, a character Code 128 cannot hold, too much data, an unknown symbology ("Errors and limits"). Run:jennifer run bcerr.j
Labels (import "label.j"):
shelf.j: a shelf label rendered as ZPL and as cab JScript ("Labels: build, render, emit", "The same label, twice"). Run:jennifer run shelf.jlabelimg.j: a picture stored on the printer, referenced from ZPL and cab ("Pictures on labels, and sending"). Run:jennifer run labelimg.jsend.jandprinter.j: send a label to a printer's raw port;printer.jis a stand-in that listens on 127.0.0.1:9100, prints one job and stops ("Pictures on labels, and sending"). Talks to the stand-in, not a printer. Run:jennifer run printer.j &thenjennifer run send.jlerr.j: data that would inject ZPL, a zero dpi, a negative quantity ("Errors and limits"). Run:jennifer run lerr.jship.j: the worked example, one shipment as a 100 x 150 mm ZPL label (ship.zpl) and as a PDF (ship.pdf) with embedded barcodes ("Worked example: the shipping label in ZPL", "The same shipment as a PDF", "The result"). Run:jennifer run ship.j, thenpdftoppm -r 150 -png ship.pdf ship && zbarimg -q ship-1.png
Scanning (@deckyard/escl):
scan.jandfakescanner.j: scan a page over eSCL, threshold it to black and white, and save it asletter.pdf("A scanned page as a PDF: @deckyard/escl", "What came back").fakescanner.jis a stand-in eSCL scanner on 127.0.0.1:8080 that answers one job withpage.jpgand stops; it is not a real scanner. Run:jennifer run fakescanner.j &thenjennifer run scan.j 127.0.0.1:8080. With a real scanner, pass itshost:portinstead.esclerr.j: the error when nothing answers on 127.0.0.1:8080 ("Errors and limits"). Run it with the fake scanner stopped:jennifer run esclerr.j
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 4.2 KiB | raw |
| bcerr.j | 453 B | raw |
| bomb.png | 75 B | |
| codes.j | 511 B | raw |
| damage.j | 423 B | raw |
| deck.toml | 277 B | raw |
| edit.j | 742 B | raw |
| esclerr.j | 264 B | raw |
| fakescanner.j | 3.1 KiB | raw |
| hostile.j | 295 B | raw |
| imgerr.j | 460 B | raw |
| info.j | 401 B | raw |
| labelimg.j | 291 B | raw |
| lerr.j | 427 B | raw |
| magick.j | 595 B | raw |
| magickerr.j | 381 B | raw |
| make-samples.sh | 1.3 KiB | raw |
| printer.j | 345 B | raw |
| qr.j | 456 B | raw |
| scan.j | 662 B | raw |
| send.j | 322 B | raw |
| shelf.j | 483 B | raw |
| ship.j | 2.4 KiB | raw |