cowmic/cowgen/tests/overlay_text_and_image.rs

34 lines
1.0 KiB
Rust
Raw Normal View History

2022-11-08 18:17:06 +00:00
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());
2023-01-12 16:00:46 +00:00
let base = Box::new(include_bytes!("assets/cow.png").to_vec());
let font = Box::new(include_bytes!("assets/OpenSans-ExtraBold.ttf").to_vec());
let superimpose = Box::new(include_bytes!("assets/mariah.jpg").to_vec());
let out = produce(
&base,
2022-11-08 18:17:06 +00:00
vec![
Element::new(
2023-01-12 16:00:46 +00:00
Media::Text(Text::new("Hello".to_string(), font, 20.0, (0, 0, 0, 128))),
2022-11-08 18:17:06 +00:00
(0, 0),
(64, 64),
),
2023-01-12 16:00:46 +00:00
Element::new(Media::Image(superimpose), (400, 400), (800, 200)),
2022-11-08 18:17:06 +00:00
],
)
.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);
}