Added mariah-cow-hello test
This commit is contained in:
parent
44fe25721b
commit
d81c0dee73
|
@ -14,3 +14,4 @@ Cargo.lock
|
|||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
cowgen/tests/out
|
||||
|
|
|
@ -85,7 +85,7 @@ impl<T: AsRef<str>, V: AsRef<Path>> Element<T, V> {
|
|||
)
|
||||
.with(
|
||||
&TextSegment::new(
|
||||
&Font::from_reader(File::open(text.font).unwrap(), 12.0).unwrap(),
|
||||
&Font::open(text.font, 12.0).unwrap(),
|
||||
text.text,
|
||||
Dynamic::Rgba(Rgba::new(
|
||||
text.fill.0,
|
||||
|
@ -140,12 +140,3 @@ impl From<MagickError> for CowError {
|
|||
CowError::Magick(m.0.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = 2 + 2;
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
After Width: | Height: | Size: 240 KiB |
|
@ -0,0 +1,40 @@
|
|||
use cowgen::*;
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::Write,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_overlay_text_and_image() {
|
||||
println!("{}", std::env::current_dir().unwrap().to_str().unwrap());
|
||||
let out = Template::new(
|
||||
include_bytes!("assets/cow.png").to_vec(),
|
||||
vec![
|
||||
Element::new(
|
||||
Media::Text(Text::new(
|
||||
"Hello",
|
||||
"tests/assets/OpenSans-ExtraBold.ttf",
|
||||
20.0,
|
||||
(0, 0, 0, 128),
|
||||
)),
|
||||
(0, 0),
|
||||
(64, 64),
|
||||
),
|
||||
Element::new(
|
||||
Media::Image(include_bytes!("assets/mariah.jpg").to_vec()),
|
||||
(400, 400),
|
||||
(800, 200),
|
||||
),
|
||||
],
|
||||
)
|
||||
.unwrap()
|
||||
.produce()
|
||||
.unwrap();
|
||||
let mut f = File::create("tests/out/one.png").unwrap();
|
||||
f.write_all(&out).unwrap();
|
||||
f.flush().unwrap();
|
||||
|
||||
let actual = fs::read("tests/out/one.png").unwrap();
|
||||
let expected = include_bytes!("expected/one.png").to_vec();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 132 KiB |
|
@ -3,29 +3,5 @@ use std::{fs::File, io::Write};
|
|||
use cowgen::{CowError, Element, Text};
|
||||
|
||||
fn main() -> Result<(), CowError> {
|
||||
let out = cowgen::Template::new(
|
||||
include_bytes!("cow.png").to_vec(),
|
||||
vec![
|
||||
Element::new(
|
||||
cowgen::Media::Text(Text::new(
|
||||
"Hello",
|
||||
"/usr/share/fonts/TTF/OpenSans-ExtraBold.ttf",
|
||||
20.0,
|
||||
(0, 0, 0, 128),
|
||||
)),
|
||||
(0, 0),
|
||||
(64, 64),
|
||||
),
|
||||
Element::new(
|
||||
cowgen::Media::Image(include_bytes!("mariah.jpg").to_vec()),
|
||||
(200, 400),
|
||||
(800, 200),
|
||||
),
|
||||
],
|
||||
)?
|
||||
.produce()?;
|
||||
let mut f = File::create("out2.png").unwrap();
|
||||
f.write_all(&out).unwrap();
|
||||
f.flush().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue