modify api to eventually allow choosing the image render mode
This commit is contained in:
parent
8893ca0c33
commit
871712388b
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue