@digitalmasterpieces/styles-client

Client for processing images via the Stylization-as-a-Service REST API by Digital Masterpieces GmbH.

Usage no npm install needed!

<script type="module">
  import digitalmasterpiecesStylesClient from 'https://cdn.skypack.dev/@digitalmasterpieces/styles-client';
</script>

README

@digitalmasterpieces/

styles-client

npm npm License npm bundle size Libraries.io dependency status for latest release, scoped npm package Type declarations

Client for processing images via the Stylization-as-a-Service REST API by Digital Masterpieces GmbH.

Installing

You can install the StylesClient using NPM or Yarn to get the latest version of our library.

npm install @digitalmasterpieces/styles-client

For usage from a CDN we recommend using Skypack CDN. The StylesClient package is accessable at the following URL:

https://cdn.skypack.dev/@digitalmasterpieces/styles-client


Usage

When using the CDN URL you need to add your script tag of type module to the HTML. Then you can initialize the client as follows:

import StylesClient from "https://cdn.skypack.dev/@digitalmasterpieces/styles-client";

const client = new StylesClient({
    apiKey: { id: "<your-key-id>", key: "<your-api-key>" },
});

Otherwise, when using Node.js in combination with TypeScript or ES modules:

import StylesClient from "@digitalmasterpieces/styles-client";

const client = new StylesClient({
    apiKey: { id: "<your-key-id>", key: "<your-api-key>" },
});

With the client initialized you can use it as follows:

import { Pipeline } from "@digitalmasterpieces/styles-client";

// Get a list of all available processing operations
const operations = await client.getOperations();

// Get a specific operation you want to use for processing
const operation = await client.getOperation(operations[0].id);

// Create a processing pipeline and use it for processing an image
const pipeline = new Pipeline();

pipeline.add(operation);

const image = /* your image to process */
const processedImage = await client.process(image, pipeline);

When using the client in browser your image should be a File. When you use the client on server-side with Node.js you could use either a Buffer or a Readable stream.

In browser this could look like:

const image = document.querySelector("#file-input").files[0];

In Node.js you could achieve it with the following:

// Using an image from file system as a readable stream
const image = {
    data: fs.createReadStream(path.join(IMAGE_DIR, "image.png")),
    mimetype: "image/png",
    name: "image.png",
};

// Using an image from file system as a buffer
const image = {
    data: fs.readFileSync(path.join(IMAGE_DIR, "image.png")),
    mimetype: "image/png",
    name: "image.png",
};

The full documentation with some usage examples is available here.

To learn more about the Stylization SDK visit our homepage at https://saas.digitalmasterpieces.com.

Get your own API key here.

Try our demo application here.

License

MIT