Skip to content
Snippets Groups Projects

ITF Barcodes Lesesaal Systematik

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Bertuch, Oliver
    Edited
    codes.sh 1.20 KiB
    #!/bin/bash
    
    set -euo pipefail
    
    # 1. You must have Python 3.x available and install a dependency: pip install python-barcode
    # 2. You must have ImageMagick installed (the convert command)
    
    # This file has the following format for each line: "<signatur>,<katalognummer>". Example: "VBA 001,7702300006"
    CODES_FILE=${1:-./codes.csv}
    
    TEMPDIR=$(mktemp -d)
    
    while read CODE
    do
        SIGNATUR=$(echo "$CODE" | cut -f1 -d",")
        NUMMER=$(echo "$CODE" | cut -f2 -d",")
    
        python3 << EOT
    from barcode import ITF
    from barcode.writer import SVGWriter
    
    # Set options (font size in pt, others are in mm)
    opts = dict(font_size=9, module_height=10.0, module_width=0.2, quiet_zone=1.0)
    writer = SVGWriter()
    
    # Render and write to file
    with open("$TEMPDIR/$SIGNATUR - $NUMMER.svg", "wb") as f:
        # The leading and trailing 0 may be replaced with other digits. Will be cut of by the reading hall scanners.
        f.write(ITF(str("0${NUMMER}0"), writer=writer).render(opts, text='$SIGNATUR - $NUMMER'))
        f.close()
    EOT
    
        convert -background none -density 600 "$TEMPDIR/$SIGNATUR - $NUMMER.svg" "$TEMPDIR/$SIGNATUR - $NUMMER.png"
    done < "$CODES_FILE"
    
    TARGETDIR=$(pwd)
    cd "$TEMPDIR";
    zip "$TARGETDIR/codes.zip" *.png
    cd -
    rm -rf "$TEMPDIR"
    • Here's the Wikipedia entry about ITF, the barcode in use. https://en.wikipedia.org/wiki/Interleaved_2_of_5

      Note that the reader expects the last digit to be the checksum (which is optional from the definition point of view and isn't used by the scanners), which typically makes our numbers have an odd number of digits. To make the number even again, the padding "0" is added in front.

      Edited by Bertuch, Oliver
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment