Skip to main content

Module image

Module image 

Source
Expand description

图片服务的 Axum 处理器。 图片服务的 Axum 处理器与处理流水线。

支持按宽度/高度、缩略图、旋转角度、输出格式/质量动态处理图片, 使用内存(moka)+ 磁盘两级缓存加速响应。 WebP 编解码走 zenwebpimage crate 未启用 WebP feature)。 本模块属于手动注册的 Axum 路由,仅在 feature = "server" 时可用。

Structs§

CachedImage 🔒
缓存条目,保存处理后的图片字节与 Content-Type。
ImageParams
图片处理查询参数。

Constants§

CACHE_DIR 🔒
DEFAULT_JPEG_QUALITY 🔒

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§

ImageFmt 🔒
detect_format 的轻量返回类型,避免在热路径上构造 image::ImageFormat。