modify api to eventually allow choosing the image render mode

This commit is contained in:
cel 🌸 2023-01-12 17:17:11 +00:00
parent 8893ca0c33
commit 871712388b
Signed by: cel
GPG Key ID: 48E29AF13B5F1349
2 changed files with 14 additions and 3 deletions

View File

@ -41,7 +41,8 @@ impl Element {
fn into_image(self) -> Result<Image, CowError> {
match self.media {
Media::Image(image) => Ok(Image::from_bytes_inferred(*image)?.resized(
// TODO: allow changing treatment of image
Media::Image((image, _)) => Ok(Image::from_bytes_inferred(*image)?.resized(
self.dimensions.0,
self.dimensions.1,
ResizeAlgorithm::Bicubic,
@ -70,7 +71,7 @@ impl Element {
pub enum Media {
Text(Text),
Image(Box<Vec<u8>>),
Image((Box<Vec<u8>>, ImageMode)),
}
pub struct Text {
@ -80,6 +81,12 @@ pub struct Text {
fill: (u8, u8, u8, u8),
}
pub enum ImageMode {
Stretch,
Fill,
Crop,
}
impl Text {
pub fn new(text: String, font: Box<Vec<u8>>, size: f32, fill: (u8, u8, u8, u8)) -> Self {
Self {

View File

@ -19,7 +19,11 @@ fn test_overlay_text_and_image() {
(0, 0),
(64, 64),
),
Element::new(Media::Image(superimpose), (400, 400), (800, 200)),
Element::new(
Media::Image((superimpose, ImageMode::Stretch)),
(400, 400),
(800, 200),
),
],
)
.unwrap();