HackFSU / feather-code

Encoding and Decoding for custom visual encoding format that extends the Code128 barcode standard.
Mozilla Public License 2.0
0 stars 0 forks source link

Barcoders crate #3

Open glfmn opened 6 years ago

glfmn commented 6 years ago

Consider using barcoders to do actual bar-code generation instead of rolling my own solution, so I can focus on getting something up and running quickly and focus time on creating necessary bindings for other languages.

glfmn commented 6 years ago

Barcoders supports the following barcode types:

And all are pretty simple to use as in:

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".to_owned()).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();

And even supports SVG files as in:

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".to_owned()).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();