opex-kandisky

1.0.4 • Public • Published

Kandisky Text-To-Image API

This is a Node.js module that wraps the Kandisky Text-To-Image API endpoint, providing an easy-to-use interface for generating images from text and various styles.

Installation

To install this module, use npm:

npm install opex-kandisky --save

Usage

Here's an example of how to use this module to generate an image:

const { generate } = require('opex-kandisky');
(async () => {
  const query = 'A beautiful sunset over the mountains';
  const style = 'ultra';
  const image1 = await generate(query, style);
  console.log(image1.url);

  const image2 = await generate(query);
  //without style
  console.log(image2.url);

  const customStyle = 'in beadwork style, intricate details made of small beads';
  const image3 = await generate(query, style);
  //with custom style
  console.log(image3.url);
})();

The generate function takes three parameters: query, style and checkSeconds. The first parameter is mandatory, and the second and third are optional. Here's what they do:

  • query: The text you want to generate an image for.
  • style: (Optional) The style of the image you want to generate. This can be empty, custom or one of the following: 'middleAges', 'anime', 'ultra', 'cyberpunk', 'kandinsky', 'aivazovsky', 'malevich', 'picasso', 'goncharova', 'classicism', 'renaissance', 'oilPainting', 'pencil', 'digital', 'sovietCartoons', 'unreal', 'cartoon', 'glamorous', 'portrait', 'mosaic', 'icon', 'khokhloma', or 'christmas'.
  • checkSeconds: (Optional) The number of seconds to wait between checking the status of the request. By default, this is set to 3 seconds.

The generate function returns an object with the following properties:

  • url: A URL to the generated image.
  • buffer: The raw image data as a buffer.
  • censored: Can be true or false. true means the prompt had forbidden words and the image was censored.

Functions

This module provides the following functions:

  • createRequest(query, style, ): Creates a new request for generating an image with the specified query and style. Returns an object with the following properties:

    • requestId: The ID of the created request.
    • success: A boolean indicating whether the request was successful.
    • message: (Optional) If success is false, this contains an error message.
  • getStatus(requestId): Gets the status of the request with the specified requestId. Returns an object with the following properties:

    • result: The current status of the request. This can be one of the following: 'INITIAL', 'PROCESSING', or 'SUCCESS'.
    • success: A boolean indicating whether the request was successful.
    • message: (Optional) If success is false, this contains an error message.
  • getResult(requestId): Gets the result of the request with the specified requestId. Returns an object with the following properties:

    • url: A URL to the generated image.
    • buffer: The raw image data as a buffer.
    • success: A boolean indicating whether the request was successful.
    • message: (Optional) If success is false, this contains an error message.
  • generate(query, style, checkSeconds): Generates an image with the specified query and style. Returns an object with the following properties:

    • url: A URL to the generated image.
    • buffer: The raw image data as a buffer.
    • success: A boolean indicating whether the request was successful.
    • message: (Optional) If success is false, this contains an error message.
  • styleNames: An array of all available style names.

  • styles: An object of all available styles and their prompts.

Credits

This module was developed by OpexDev, and is licensed under the ISC License.

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i opex-kandisky

    Weekly Downloads

    1

    Version

    1.0.4

    License

    ISC

    Unpacked Size

    23.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • oreh-orehov