| Crates.io | axum-image-endpoint |
| lib.rs | axum-image-endpoint |
| version | 0.1.1 |
| created_at | 2025-11-10 16:08:52.930883+00 |
| updated_at | 2025-11-27 12:53:41.973748+00 |
| description | Image Endpoint to upload big images and receive rescaled ones |
| homepage | |
| repository | https://github.com/firewave-remo/axum-image-endpoint |
| max_upload_size | |
| id | 1925776 |
| size | 207,609 |
Utility Crate for upload and especially downloading/resizing images.
Take a closer look at the examples folder.
use std::{error::Error, net::SocketAddr};
use axum::Router;
use axum_image_endpoint::{image_app::image_app, image_app_options::ImageAppOptions};
use tokio::net::TcpListener;
use tower_http::services::{ServeDir, ServeFile};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let app = image_app(ImageAppOptions::default())?; // create image app
let serve_dir = ServeDir::new("./examples/dist")
.not_found_service(ServeFile::new("./examples/dist/index.html")); // This is just to serve the example HTML
let router = Router::new().fallback_service(serve_dir);
let router = router.merge(app);
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
let listener = TcpListener::bind(addr).await?;
dbg!(listener.local_addr()?);
axum::serve(listener, router).await?;
Ok(())
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Basic Server Example</title>
<style>
img {
width: 100%;
}
</style>
</head>
<body>
<h1>Basic Server</h1>
<div>
Boo
</div>
<!-- show the original image -->
<img src="/api/img/partner/image.jpg">
<!-- change the image to a webp image -->
<img src="/api/img/partner/image.jpg?imgtype=Webp" alt="">
<!-- roate the image by 90 deg -->
<img src="/api/img/image.jpg?rotate=90" alt="">
<!-- change the width of the image to 120px -->
<img src="/api/img/image.jpg?width=120" alt="">
</body>
</html>
Possible query parameters:
rotate -> rotate images
width -> change width of the image, keeps ratio
height -> change height of the image, keeps ratio
grayscale -> change image to grayscale
quality -> change quality of the image to reduce file size. Works for Jpg and Webp
imgtype -> change from original imgtype to this type. Supported Img Types are Jpeg/Jpg, Png, Webp
cargo run --example basic_server --release
Image resizing can be pretty slow in debug mode.
Test Image Photo by Peter Thomas on Unsplash