@enslo/sd-metadata-lite
v1.1.0
Published
Lightweight AI image metadata reader for bookmarklets
Maintainers
Readme
@enslo/sd-metadata-lite
🌐 日本語版はこちら
A lightweight, read-only metadata parser for AI-generated images. Designed for bookmarklets and userscripts where bundle size matters.
- Tiny: 6,519 bytes minified IIFE build
- Read-only: Extracts metadata and returns A1111-format text
- Zero dependencies: Works in Node.js and browsers
- 18+ tools: Supports all major AI image generation tools
[!TIP] Need write support, format conversion, or structured metadata? Use the full library instead.
Installation
npm install @enslo/sd-metadata-liteUsage
ESM
import { parse } from '@enslo/sd-metadata-lite';
const response = await fetch(imageUrl);
const data = new Uint8Array(await response.arrayBuffer());
const text = parse(data);
if (text) {
console.log(text);
// masterpiece, best quality, 1girl
// Negative prompt: lowres, bad quality
// Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 12345, ...
}Userscript
Load the IIFE build via @require:
// ==UserScript==
// @name My Script
// @namespace https://example.com
// @require https://cdn.jsdelivr.net/npm/@enslo/[email protected]/dist/index.global.js
// ==/UserScript==
const response = await fetch(imageUrl);
const data = new Uint8Array(await response.arrayBuffer());
const text = sdml.parse(data);
if (text) {
console.log(text);
}[!TIP] Always pin to a specific version in
@requirefor stability.
Bookmarklet
Most sites block external script loading via CSP. Instead, paste the IIFE bundle inline:
- Copy the contents of
dist/index.global.js(or download from npm) - Build your bookmarklet with the code inlined:
javascript:void(async()=>{/* paste contents of index.global.js here */;/* your code using sdml.parse() */})()Since the IIFE assigns to var sdml, calling sdml.parse() works immediately after the inlined code.
API
parse(input: Uint8Array | ArrayBuffer): string
Parses metadata from an image and returns A1111-format text.
Parameters:
input- Image file data (PNG, JPEG, or WebP)
Returns:
- A1111-format metadata string if metadata is found
- Empty string (
"") if no metadata is found or the format is unrecognized
Output Format
The output follows the Stable Diffusion WebUI (A1111) text format:
masterpiece, best quality, 1girl
Negative prompt: lowres, bad quality
Steps: 20, Sampler: Euler a, Schedule type: Karras, CFG scale: 7, Seed: 12345, Size: 512x768, Model hash: a1b2c3d4, Model: model.safetensorsFields are included only when present in the source metadata.
Supported Tools
Reads PNG, JPEG, and WebP metadata from:
- Stable Diffusion WebUI (A1111)
- Forge / Forge Classic / Forge Neo
- reForge / EasyReforge
- NovelAI
- ComfyUI
- SD.Next
- InvokeAI
- SwarmUI
- Stability Matrix
- Civitai (JPEG only verified; PNG/WebP are experimental *)
- TensorArt
- HuggingFace Space
- Ruined Fooocus
- Fooocus *
- Easy Diffusion *
[!NOTE] * Implemented based on reference code analysis, not verified with actual sample files.
Globals
When loaded via <script> tag or userscript @require, the IIFE build exposes:
window.sdml.parse(input)Contributing
See CONTRIBUTING.md for guidelines.
License
MIT
