/stable-diffusion-image-metadata

stable diffusion image metadata

Primary LanguageTypeScript

stable-diffusion-image-metadata

This tool provides the capability to extract and parse metadata from images. It is inspired by the work of the civitai project and leverages some of their code for image metadata parses

About for the processing of parameters, there are two steps.

  • (1) Preprocessing, which extracts special attributes in a 'RegExp'
  • (2) Extracting the primary attributes with 'split(': ') and split(', ')'

Installation

npm install --save stable-diffusion-image-metadata

Dependencies

{
  "exifreader": "^4.13.0"
}

Usage

export { extract, parse, stringify } from 'stable-diffusion-image-metadata';

const image = 'https://image.png'; // or File | base64

const [parameters, isParameters] = await extract(image);

const metadata = parse(parameters);

const metadataStr = stringify(metadata);

Changelog

[1.0.11] - 2023-09-09

  • fixed parse: make preprocess config, there will already be more preprocessing configs in the future.
const preproccessConfigs = [
  { reg: /(ControlNet \d+): "([^"]+)"/g },
  { reg: /(Lora hashes): "([^"]+)"/g },
  { reg: /(Hashes): ({[^}]+})/g, key: 'hashes', value: preproccessFormatJSONValueFn },
  //...There should be many configs that need to be preprocessed in the future
];

[1.0.10] - 2023-09-09

  • remove 'buffer-big-endian.ts'
  • fixed function 'extract' chinese problem