0.0.6 • Published 8 months ago

chilled-lemon v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Test

This library provides functionality to extract information stored within PNG images generated by Stable Diffusion Web UI.

It also provides functions to mutually convert between infotext and JSON formats.

Usage(extract infotext in PNG images)

You can use getInfotext or getInfotextJson to extract infotext embedded in PNG images.

Support CJS/ESM/UMD

CommonJS

const { getInfotext, getInfotextJson } = require('chilled-lemon');
const { readFile } = require('node:fs/promises');

(async () => {
    const buf = await readFile('./test.png');

    const infotext = await getInfotext(buf);
    console.log(infotext);

    const json = await getInfotextJson(buf);
    console.log(json);
})();

ES Modules

import { getInfotext, getInfotextJson } from 'chilled-lemon';
import { readFile } from 'node:fs/promises';

const buf = await readFile('./test.png');

const infotext = await getInfotext(buf);
console.log(infotext);

const json = await getInfotextJson(buf);
console.log(json);

UMD

<!DOCTYPE html>
<html>

<head>
    <script src="/node_modules/chilled-lemon/dist/index.umd.js"></script>
</head>

<body>
    <input type="file" id="inputFile" />
    <button onclick="getPngInfoFromFile()">Get PNG Info</button>
    <pre id="output"></pre>

    <script>
        const { getInfotext, getInfotextJson } = window.ChilledLemon;

        async function getPngInfoFromFile() {
            const fileInput = document.getElementById('inputFile');
            const file = fileInput.files[0];
            const arrayBuffer = await file.arrayBuffer();

            try {
                const outputElement = document.getElementById('output');

                const infotext = await getInfotext(arrayBuffer);
                outputElement.textContent += '\n\n===PNG INFO (infotext format)===\n' + infotext;

                const json = await getInfotextJson(arrayBuffer);
                outputElement.textContent += '\n\n===PNG INFO (JSON format)===\n' + JSON.stringify(json);
            } catch (err) {
                console.error(`Error reading file: ${err.message}`);
            }
        }
    </script>
</body>

</html>

Usage (Conversion between infotext and JSON)

You can use convertInfotextToJson and convertJsonToInfotext to convert between infotext and JSON.

import { getInfotext, getInfotextJson, convertInfotextToJson, convertJsonToInfotext } from 'chilled-lemon';
import { readFile } from 'node:fs/promises';

const buf = await readFile('./test.png');

const infotext = await getInfotext(buf);
const convertedJson = await convertInfotextToJson(infotext);
console.log(convertedJson)

const json = await getInfotextJson(buf);
const convertedInfotext = await convertJsonToInfotext(json);
console.log(convertedInfotext);

Development

Code formatter

We are currently utilizing "deno fmt" as our code formatter. In order to use this, developers will need to have Deno installed on their PC.

At the moment, I am the sole developer working on this project, which is why I chose "deno fmt".
it allows for easy code formatting without the necessity to include dependent packages in the project.

In the future, should we expand our team and if other developers express a preference for a different formatter, I am open to discussions and would appreciate if the suggestions are raised as issues for consideration.

inspired

The idea for this source code was inspired by this blog post (Japanese post).

License

MIT

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

9 months ago

0.0.2

10 months ago

0.0.1

10 months ago