pub struct Template { /* private fields */ }Expand description
A Template holds information about a number of JPEG images, and serves as an
input to ImageGenerator.
Use Template::from_input or Template::from_inputs if you know your
inputs ahead of time, otherwise create an empty template with
Template::default and fill it up with Template::learn or Template::learn_many.
§Examples
use fakejpeg::Template;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let images = [
// images come here...
];
let template = Template::from_inputs(&images)?;
// Do something with `template`, maybe generate new fakes from it!
Ok(())
}Implementations§
Source§impl Template
impl Template
Sourcepub fn from_input<I: AsRef<[u8]>>(input: I) -> Result<Self, ParseError>
pub fn from_input<I: AsRef<[u8]>>(input: I) -> Result<Self, ParseError>
Parses and learns the structure of a single JPEG images, returning a Template.
§Errors
Returns ParseError when parsing fails.
Sourcepub fn from_inputs<A, I>(inputs: I) -> Result<Self, ParseError>
pub fn from_inputs<A, I>(inputs: I) -> Result<Self, ParseError>
Parses and learns the structure of multiple JPEG images, returning a Template.
Similar to Template::from_input, but rather than taking parsing and
learning a single JPEG image, it does so over multiple of them.
§Errors
Returns ParseError when parsing fails.
Sourcepub fn learn<A: AsRef<[u8]>>(&mut self, input: A) -> Result<(), ParseError>
pub fn learn<A: AsRef<[u8]>>(&mut self, input: A) -> Result<(), ParseError>
Parse and learn the structure of a single JPEG image.
This parses the JPEG, and extracts the parts required to generate randomized fakes, and updates the template.
§Errors
Returns ParseError when parsing fails.
Sourcepub fn learn_many<A, I>(&mut self, inputs: I) -> Result<(), ParseError>
pub fn learn_many<A, I>(&mut self, inputs: I) -> Result<(), ParseError>
Parses and learns the structure of multiple JPEG images.
Similar to Template::learn, but rather than taking parsing and
learning a single JPEG image, it does so over multiple of them.
§Errors
Returns ParseError when parsing fails.