Last active
November 7, 2018 22:59
-
-
Save bernardobelchior/46f3b6acf8cc22aa2abb3de537dd9457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn encode_png_image(image: DynamicImage) -> Result<Vec<u8>, ImageError> { | |
let mut result: Vec<u8> = Vec::new(); // Creates the output `Vec<u8>` | |
image.write_to(&mut result, ImageOutputFormat::PNG)?; // Writes `image` to `result` as a PNG | |
Ok(result) | |
} | |
fn main() { | |
lambda::gateway::start(|req| { | |
//... | |
let thumbnail = image.thumbnail(128, 128); | |
let encoded_thumbnail = encode_png_image(thumbnail)?; // Encode image as PNG | |
let encoded_thumbnail = base64::encode(&encoded_thumbnail); // Encode PNG as base64 | |
//... | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment