Expand description
图片服务的 Axum 处理器。 图片服务的 Axum 处理器与处理流水线。
支持按宽度/高度、缩略图、旋转角度、输出格式/质量动态处理图片,
使用内存(moka)+ 磁盘两级缓存加速响应。
WebP 编解码走 zenwebp(image crate 未启用 WebP feature)。
本模块属于手动注册的 Axum 路由,仅在 feature = "server" 时可用。
Structs§
- Cached
Image 🔒 - 缓存条目,保存处理后的图片字节与 Content-Type。
- Image
Params - 图片处理查询参数。
Constants§
Statics§
- IMAGE_
CACHE 🔒 - IMAGE_
DIMENSIONS_ 🔒CACHE - 图片尺寸缓存(moka sync)。key = 相对路径如 “2026/06/22/x.webp”。 用 sync cache 而非 future cache:render_markdown_enhanced 是同步函数,不能 .await。
- MAX_
IMAGE_ DIMENSION - 图片单边(宽或高)尺寸上限,单位像素。
- MAX_
IMAGE_ PIXELS - 允许处理的最大图片像素数(默认约 7k x 7k)。
Functions§
- check_
image_ 🔒dimensions - content_
type 🔒 - detect_
format 🔒 - disk_
cache_ 🔒base - etag_
for 🔒 - etag_
matches 🔒 - get_
image_ dimensions - 读取图片真实尺寸(只读 header,不解码像素)。
- image_
reader_ 🔒limits - 构造统一的 image::Limits(宽度/高度/分配上限),供 upload 与 image serving 共享。
- image_
response 🔒 - invalidate_
asset_ caches - 素材删除时清理其派生缓存。
- is_
path_ 🔒safe - 校验请求路径不会逃出 uploads 目录。
- process_
image 🔒 - process_
image_ 🔒blocking - read_
dimensions_ 🔒by_ mime - 按 MIME 只读 header 拿 (width, height)。失败返回损坏错误。
- read_
dimensions_ 🔒from_ bytes - 按扩展名分发:webp 走 zenwebp header,gif/png/jpeg 走 image crate。
- read_
disk_ 🔒cache - read_
image_ 🔒dimensions - 读 image crate 支持格式(jpeg/png/gif)的 header 拿尺寸。
- read_
webp_ 🔒dimensions - 读 WebP header 拿尺寸(zenwebp 只解析 RIFF header,不解码像素)。
- serve_
image - 图片访问与动态处理的 Axum handler。
- upload_
dimensions 🔒 - 仅读取 header 校验上传图片的尺寸/像素是否超限,并返回 (width, height)。
- write_
disk_ 🔒cache
Type Aliases§
- Image
Fmt 🔒 - detect_format 的轻量返回类型,避免在热路径上构造 image::ImageFormat。