Skip to content

Instantly share code, notes, and snippets.

@bernardobelchior
Last active November 7, 2018 22:59
Show Gist options
  • Save bernardobelchior/46f3b6acf8cc22aa2abb3de537dd9457 to your computer and use it in GitHub Desktop.
Save bernardobelchior/46f3b6acf8cc22aa2abb3de537dd9457 to your computer and use it in GitHub Desktop.
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