buntine / barcoders

A barcode encoding library for the Rust programming language
Apache License 2.0
164 stars 24 forks source link

Example code outputting to an image::RgbImage #8

Closed tl8roy closed 7 years ago

tl8roy commented 7 years ago

It would be useful to be able to output the barcode to a image::RgbImage variable.

I assume that this is quite easy to do, but it would be easier to work out if there is an example that shows the operation.

buntine commented 7 years ago

Good idea. I'll add in some additional functionality to the image generator so that it may return an image::ImageBuffer object.

buntine commented 7 years ago

I've added this in as an optional method on the image generator, which returns an image::ImageBuffer instead of a Vec<u8>.

Usage will be something along the lines of this:

let itf = TF::interleaved("98766543561".to_owned()).unwrap();
let img = Image::ImageBuffer {
    height: 130,
    xdim: 1,
    rotation: Rotation::Zero,
};
let generated = img.generate_buffer(&itf.encode()[..]).unwrap();

This is staged for the 0.8.0 release. I just need to add some more tests and update the documentation.

I'll close this now. Open it back up if you have any more comments. Thanks!

tl8roy commented 7 years ago

Cool. I will definitely have a play with this.

buntine commented 7 years ago

Ok, I've published version 0.8.0 to crates.io.

I've updated the README with examples on generating a barcode to an image buffer. I've also allowed for setting background/foreground/opacity in the native image generators.

Thanks!