Function matrix_sdk::attachment::generate_image_thumbnail

source ·
pub fn generate_image_thumbnail<R: BufRead + Seek>(
    content_type: &Mime,
    reader: R,
    size: Option<(u32, u32)>,
    format: ThumbnailFormat
) -> Result<Thumbnail, ImageError>
Available on crate feature image-proc only.
Expand description

Generate a thumbnail for an image.

This is a convenience method that uses the image crate.


  • content_type - The type of the media, this will be used as the content-type header.

  • reader - A Reader that will be used to fetch the raw bytes of the media.

  • size - The size of the thumbnail in pixels as a (width, height) tuple. If set to None, defaults to (800, 600).

  • format - The image format to use to encode the thumbnail.


use std::{io::Cursor, path::PathBuf};

use matrix_sdk::attachment::{
    generate_image_thumbnail, AttachmentConfig, Thumbnail, ThumbnailFormat,
use mime;
let path = PathBuf::from("/home/example/my-cat.jpg");
let image = tokio::fs::read(path).await?;

let cursor = Cursor::new(&image);
let thumbnail = generate_image_thumbnail(
let config = AttachmentConfig::with_thumbnail(thumbnail);

if let Some(room) = client.get_room(&room_id) {