Version 0.1.0
Server-Side Image Resolution (`@m2d/image-node`)
Updated 5 min ago
Headless image and SVG resolution using sharp in Node.js environments.
@m2d/image-node is designed specifically for backend and server-side environments where browser APIs like document.createElement("canvas") or Image() are unavailable.
Supported Source Formats
- Local Filesystem Paths:
Relative or absolute paths on the server. Configure
pathPrefixto anchor relative image paths to your static assets orpublic/directory:nodeImagePlugin({ pathPrefix: "./public", }); - Remote HTTPS/HTTP URLs:
Fetched directly using Node's native
fetchand streamed into memory buffers. - Data URLs:
Base64-encoded images (
data:image/png;base64,...) are decoded into raw Buffers. - SVG AST Nodes:
SVGs emitted by diagram plugins (such as
@m2d/mermaid-node) are rasterized directly into high-resolution PNGs viasharpandlibrsvg.
Sharp Rasterization Pipeline
Images are processed through sharp:
- Metadata inspection determines native pixel dimensions without fully decoding the entire image upfront.
calculateDimensionsscales images proportionally to ensure they do not exceedmaxW(default: 6 inches) ormaxH(default: 8 inches) based on the target documentdpi(default: 96).- Unsupported formats (WEBP, AVIF, TIFF, SVG) are automatically converted into Word-compatible PNG or JPEG raster buffers.