Code Monkey home page Code Monkey logo

chilled-lemon's Introduction

project logo

chilled-lemon

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.
An example of the code can also be found here

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

chilled-lemon's People

Contributors

shinshin86 avatar

Watchers

 avatar  avatar  avatar

chilled-lemon's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.