From 871712388ba34b668885586a56abed29e60dd622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Thu, 12 Jan 2023 17:17:11 +0000 Subject: [PATCH] modify api to eventually allow choosing the image render mode --- cowgen/src/lib.rs | 11 +++++++++-- cowgen/tests/overlay_text_and_image.rs | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cowgen/src/lib.rs b/cowgen/src/lib.rs index 4812167..c9b59aa 100644 --- a/cowgen/src/lib.rs +++ b/cowgen/src/lib.rs @@ -41,7 +41,8 @@ impl Element { fn into_image(self) -> Result { 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>), + Image((Box>, 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>, size: f32, fill: (u8, u8, u8, u8)) -> Self { Self { diff --git a/cowgen/tests/overlay_text_and_image.rs b/cowgen/tests/overlay_text_and_image.rs index c2f9f01..09cd179 100644 --- a/cowgen/tests/overlay_text_and_image.rs +++ b/cowgen/tests/overlay_text_and_image.rs @@ -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();