@tola-scripts/image
查看图片元数据,或将本地图片缩放、裁剪并转换格式。
main
tola nu @tola-scripts/image列出子命令(metadata 与 resize)。
metadata
tola nu @tola-scripts/image metadata <source>以 JSON 输出图片的像素宽高(width、height)、格式(format)及透明通道信息(has-alpha)。
位置参数
sourcepath必填:图片文件路径,相对于当前工作目录解析。
查看本地 PNG 图片信息
tola nu @tola-scripts/image metadata photo.pngresize
tola nu @tola-scripts/image resize <source> [OPTIONS]缩放、裁剪或转换本地图片(支持 SVG),输出为新文件或原始字节。
SVG 引用的图片必须以内嵌 data URI 形式提供。站点 hook 渲染 SVG 文字时会自动沿用站点的 [typst.fonts] 配置;独立运行时可在脚本名前传入 --config tola.toml 以加载站点字体。
位置参数
sourcepath必填:源图片路径,支持常见位图及 SVG。
选项
--output,-opath:在已有目录下创建新文件保存结果,并以 JSON 打印生成后的图片元数据;省略时返回原始图片字节。--widthint:目标宽度(正整数像素)。fit-width、scale、fit与fill必填。--heightint:目标高度(正整数像素)。fit-height、scale、fit与fill必填。--opstring:缩放模式:fit-width/fit-height(按单边等比缩放)、fit(等比完整放入框内且不放大)、fill(裁剪填充至精确尺寸)、scale(直接拉伸)。省略时,仅给一边按比例缩放,两边都给则裁剪,均不给则保持原尺寸。--anchorstring默认值:'center':fill裁剪时的保留锚点,默认center;也可选top、bottom、left、right、top-left、top-right、bottom-left或bottom-right。其他模式仅接受center。--formatstring默认值:'auto':输出格式:png、webp、jpg、jpeg或auto。位图设为auto时,无透明通道的有损源图输出 JPEG,其余输出 PNG;SVG 必须显式指定位图格式。--qualityint:编码质量:JPEG 取1..100(默认75),WebP 取0..100(省略时无损),PNG 忽略该项。--filterstring默认值:'lanczos3':位图重采样滤镜,默认lanczos3;也可选nearest、triangle、catmull-rom或gaussian。--backgroundstring:填充透明区域的六位十六进制底色(如'#ffffff')。含透明通道的图片转为 JPEG 时必填。
按宽度等比生成 WebP 预览图
tola nu @tola-scripts/image resize photo.png --width 640 --format webp --output preview.webp顶部对齐裁剪方形缩略图
tola nu @tola-scripts/image resize photo.png --width 160 --height 160 --anchor top --format webp --output square.webp使用站点字体光栅化 SVG
tola nu --config tola.toml @tola-scripts/image resize wordmark.svg --width 240 --format png --output wordmark.png