Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Barcoders crate #3

Open
glfmn opened this issue Sep 28, 2017 · 1 comment
Open

Barcoders crate #3

glfmn opened this issue Sep 28, 2017 · 1 comment
Assignees
Milestone

Comments

@glfmn
Copy link
Member

glfmn commented Sep 28, 2017

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 glfmn added this to the 0.1 milestone Sep 28, 2017
@glfmn glfmn self-assigned this Sep 28, 2017
@glfmn glfmn changed the title Barcoders Barcoders crate Sep 28, 2017
@glfmn
Copy link
Member Author

glfmn commented Sep 28, 2017

Barcoders supports the following barcode types:

  • EAN-13
    • UPC-A
    • JAN
    • Bookland
  • EAN-8
  • EAN Supplementals
    • EAN-2
    • EAN-5
  • Code39
  • Code128
  • Two-Of-Five
    • Interleaved (ITF)
    • Standard (STF)
  • Codabar

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();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant