@enslo/sd-metadata-lite
v1.3.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,911 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
- For PNGs with no generation parameters, the C2PA Content Credentials generator name (e.g.
OpenAI Media Service API,Google C2PA Core Generator Library) when present - 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.safetensorsPrompt and parameter fields 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.
Content Credentials (C2PA)
PNGs from commercial tools that sign their output with C2PA Content Credentials are detected by their generator name instead of generation parameters:
- OpenAI ChatGPT
- Google Gemini
For these images parse() returns the generator name (e.g. OpenAI Media Service API). Detection is best-effort: the credentials are easily stripped by re-saving or re-uploading, and a present manifest is not cryptographically verified.
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
