• Stars
    star
    156
  • Rank 232,163 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A barcode encoding library for the Rust programming language

Build Status Coverage Status MIT licensed Crates.io Algorithmia

BARCODERS

Barcoders is a barcode-encoding library for the Rust programming language.

Barcoders allows you to encode valid data for a chosen barcode symbology into a Vec<u8> representation of the underlying binary structure. From here, you can take advantage of one of the optional builtin generators (for exporting to SVG, GIF, PNG, etc) or build your own.

Installation

For encode-only functionality (e.g if you just want to translate a String into a Vec<u8> of binary digits):

[dependencies]
barcoders = "1.0.2"

If you want to generate barcodes into a particular format, turn on the appropriate feature(s):

[dependencies]
barcoders = {version = "1.0.2", features = ["image", "ascii", "svg", "json"]}

Each generator is an optional feature so you only need to compile what you want to use. See below for the feature associated to the generation functionality you desire.

Documentation

Documentation and examples are available here.

Current Support

The ultimate goal of Barcoders is to provide encoding support for all major (and many not-so-major) symbologies.

Symbologies

  • EAN-13
    • UPC-A
    • JAN
    • Bookland
  • EAN-8
  • EAN Supplementals
    • EAN-2
    • EAN-5
  • Code11
    • USD-8
  • Code39
  • Code93
  • Code128 (A, B, C)
  • Two-Of-Five
    • Interleaved (ITF)
    • Standard (STF)
  • Codabar
  • More coming!

Generators

  • ASCII (feature: ascii)
  • JSON (feature: json)
  • SVG (feature: svg)
  • PNG (feature: image)
  • GIF (feature: image)
  • JPEG (feature: image)
  • Image Buffer (feature: image)
  • Or add your own

Examples

Encoding

extern crate barcoders;

use barcoders::sym::ean13::*;

// Each encoder accepts a String to be encoded. Valid data is barcode-specific
// and thus constructors return an Result<T, barcoders::error::Error>.
let barcode = EAN13::new("593456661897").unwrap();

// The `encode` method returns a Vec<u8> of the binary representation of the
// generated barcode. This is useful if you want to add your own generator.
let encoded: Vec<u8> = barcode.encode();

Image (GIF, JPEG, PNG) generation

extern crate barcoders;

use barcoders::sym::code39::*;
use barcoders::generators::image::*;
use std::io::prelude::*;
use std::io::BufWriter;
use std::fs::File;
use std::path::Path;

let barcode = Code39::new("1ISTHELONELIESTNUMBER").unwrap();
let png = Image::png(80); // You must specify the height in pixels.
let encoded = barcode.encode();

// Image generators return a Result<Vec<u8>, barcoders::error::Error) of encoded bytes.
let bytes = png.generate(&encoded[..]).unwrap();

// Which you can then save to disk.
let file = File::create(&Path::new("my_barcode.png")).unwrap();
let mut writer = BufWriter::new(file);
writer.write(&bytes[..]).unwrap();

// Generated file ↓ ↓ ↓

Code 39: 1ISTHELONELIESTNUMBER

You can also request an image::RgbaImage, which you can manipulate yourself:

let barcode = Code39::new("BEELZEBUB").unwrap();
let buffer = Image::image_buffer(100);
let encoded = barcode.encode();
let img = buffer.generate_buffer(&encoded[..]).unwrap();

// Manipulate and save the image here...

You may also specify the barcode x-dimension, rotation, background/foreground colors and opacity by specifying the struct fields:

let gif = Image::GIF{height: 80,
                     xdim: 1,
                     rotation: Rotation::Zero,
                     // Using non black/white colors is generally not recommended by most vendors, but barcoders makes it possible.
                     foreground: Color::new([255, 0, 0, 255]),
                     background: Color::new([0, 255, 20, 255])};

SVG generation

SVG is similar to the other image types, but I've supplied it as a separate feature as it doesn't require third-party dependencies.

extern crate barcoders;

use barcoders::sym::code39::*;
use barcoders::generators::svg::*;
use std::io::prelude::*;
use std::io::BufWriter;
use std::fs::File;
use std::path::Path;

let barcode = Code39::new("56DFU4A777H").unwrap();
let svg = SVG::new(200); // You must specify the height in pixels.
let encoded = barcode.encode();
let data: String = svg.generate(&encoded).unwrap();

let file = File::create(&Path::new("my_barcode.svg")).unwrap();
let mut writer = BufWriter::new(file);
writer.write(data.as_bytes()).unwrap();

You may also specify the barcode x-dimension, background/foreground colors and opacity by specifying the struct fields:

let svg = SVG{height: 80,
              xdim: 1,
              // Using non black/white colors is generally not recommended by most vendors, but barcoders makes it possible.
              foreground: Color::black(),
              background: Color::new([0, 255, 20, 255])};

ASCII generation

The ASCII generator is useful for testing purposes.

extern crate barcoders;

use barcoders::sym::ean13::*;
use barcoders::generators::ascii::*;

let barcode = EAN13::new("750103131130").unwrap();
let encoded = barcode.encode();

let ascii = ASCII::new();
ascii.generate(&encoded[..]);

assert_eq!(ascii.unwrap(),
"
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
# # ##   # #  ###  ##  # #  ### #### # ##  ## # # #    # ##  ## ##  ## #    # ###  # ### #  # #
".trim());

JSON generation

This may be useful for passing encoded data to third-party systems in a conventional format.

extern crate barcoders;

use barcoders::sym::codabar::*;
use barcoders::generators::json::*;

let codabar = Codabar::new("A98B").unwrap();
let json = JSON::new();
let generated = json.generate(&codabar.encode()[..]);

assert_eq!(generated.unwrap(),
"
{
 \"height\": 10,
 \"xdim\": 1,
 \"encoding\": [1,0,1,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,0,1,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0,1,1]
}
"

Tests

Note, if you want to output actual image/svg files to the filesystem for visual confirmation, set the WRITE_TO_FILE variable in the appropriate test modules.

Full suite:

$ cargo test --features="image svg ascii json"

Encoding only:

$ cargo test

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

SwervinMervin

A truly radical homage to 16-bit racing games.
Python
228
star
2

discogs

A Ruby wrapper of the Discogs.com API
Ruby
218
star
3

Simply-Scheme-Exercises

All of the exercises (and their solutions!) from the Berkeley textbook Simply Scheme.
Scheme
110
star
4

MoonDweller

A text-based adventure. You will definitely die.
Clojure
65
star
5

pioneers

An interactive study of the impact of pioneers in the field of computer science.
TypeScript
26
star
6

CarEngines

Some simple techniques for generating car engine sound effects
JavaScript
18
star
7

Medieval-Alien-Massacre

A sadistic, pro-death text-based adventure for children.
Clojure
17
star
8

Dim-Jump

A fried Dim Sim on the run with nothing to lose
Lua
16
star
9

wrestlers-adapter

TCP -> HTTP adapter for alerting on wifi events.
Rust
16
star
10

Haskell--Craft-of-FP

My progress through "Haskell: The Craft of Functional Programming (2nd edition)" by Simon Thompson
Haskell
15
star
11

laser-drift

Reverse engineered Carrera Digital 132/124 infrared controller suite
Python
14
star
12

basmap

Buntine's Awesome SiteMap Audit Program
Rust
10
star
13

discogs-oauth

An example app for authenticating with OAuth using my Discogs library.
Ruby
8
star
14

necroblaster

A rhythm game for the metal-obsessed.
Lua
7
star
15

love2d-top-down-shooter

A prototype top-down shooter game
Lua
5
star
16

bolverk

An 8-bit microprocessor emulator, built for educational purposes.
Ruby
5
star
17

rust-crawler

A simple website crawler in Rust.
Rust
4
star
18

traka

Rails plugin for tracking changes to resources over time.
Ruby
3
star
19

Life-is-a-game

Conway's Game of Life implemented in PLT Scheme
Scheme
3
star
20

love2d-tiled-sti

2D Platformer experiments with Lua, Love2d, Tiled, STI and others
Lua
3
star
21

carrera-champs

Python
3
star
22

merb-restful-links

A Merb plugin that allows you to make "RESTful requests" with the link_to helper method.
3
star
23

dimjump

A fried Dim Sim on the run with nothing to lose...
Clojure
3
star
24

witchhammer

A firefox extension to easily find bands and albums at metal-archives.com
JavaScript
3
star
25

ternary-machines

Notes and examples for an essay
2
star
26

trafficlive

A Python wrapper of the TrafficLive API
Python
2
star
27

dots

For Mel
Clojure
2
star
28

RubySwift

A Ruby wrapper of the Swift Digital Suite API
Ruby
2
star
29

Our-sites

A Clojure web app (Compojure) to display the sites hosted on our staging server.
Clojure
2
star
30

algo2

Rust
2
star
31

dm-multi-hooks

A DataMapper plugin that allows you to assign multiple hook methods easily
2
star
32

Bolverk-Assembler

An assembly language compiler for the Bolverk microprocessor emulator.
Ruby
2
star
33

valshamr

A collection of small, integrated tools that perform some common IPv6 related tasks.
Ruby
2
star
34

Fractals

My experiments in generating fractal art with Scheme
Scheme
1
star
35

rust-playground

My playground for learning Rust. Expect horrible code.
Rust
1
star
36

started-from-the-bottom

Tribute to Drake
JavaScript
1
star
37

Dubstep-Makes-You

JavaScript
1
star
38

p-prime-prime

1
star
39

bunts-io

Bunts.io
Clojure
1
star
40

ir-plot

Python
1
star
41

bolverk_ui

A Sinatra application, which provides a UI for the Bolverk machine emulator
JavaScript
1
star
42

Quick-ROT13

A Mozilla Firefox extension to quickly apply a ROT13 or ROT47 cipher to a body of text.
JavaScript
1
star
43

The-Solar-System-is-Badass

A parallax demo for my presentation at Web Directions
JavaScript
1
star
44

picster

Example app for my web dev students
Ruby
1
star
45

Lisp-Brainfuck-REPL

A brainfuck REPL implemented in Scheme
Scheme
1
star
46

Brainfuck-Yo-self

A basic brainfuck interpreter in Python.
Python
1
star
47

daily_hunks

Daily Hunks for the Bergcloud Little Printer. Hot piece o' ass on demand.
Ruby
1
star
48

cd_git_branch

A "cd" replacement that warns you about non-master branches of a Git repository
Python
1
star
49

jquery.colorChars.js

The most important JQuery plugin in the universe: Colors character groups in a collection of elements.
JavaScript
1
star
50

blobber

A simple Javascript example for my web dev students
JavaScript
1
star