npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

picsart-creative-apis-ts-sdk

v1.0.0

Published

Picsart Creative APIs SDK. Includes helper methods and functions for Programmable Image APIs (e.g. Remove Background, Upscale, Enhance, Effects) and the GenAI APIs (e.g. Text2Image, Replace, Expand Image).

Downloads

5

Readme

PICSART CREATIVE APIS

Description

This is a TypeScript SDK of Picsart Programmable Image APIs and Picsart GenAI APIs. You can easily do many actions with your images just by adding few lines of code to your JavaScript or Typescript projects.

Installation

To install the package, run the following command:

npm install --save picsart-creative-apis-ts-sdk

Usage

Get an API instance

import  PicsartEnterprise from "picsart-creative-apis-ts-sdk";

// Get an instance of image API
const imageApi = PicsartEnterprise.createImageApi('YOUR_API_KEY');

// Get an instance of GenAI API
const genaiApi = PicsartEnterprise.createGenAIApi('YOUR_API_KEY');

Create an Image instance

// From public image url
const imageSource = ImageApi.fromUrl('https://....');

// From Picsart image id
const imageSource = ImageApi.fromImageId('your-image-id-here');

// From binary
const fileContent = fs.readFileSync("examples/image.png");
const imageSource = ImageApi.fromFile(fileContent);

// From stream
const readStream = fs.createReadStream("examples/image.png");
const imageSource = ImageApi.fromStream(readStream);

Remove background

  const result = await imageApi.removeBackground(
      new RemoveBackgroundRequest()
        .setImage(imageSource)
        .setBgColor("green")
    );

  console.log(result.image.url);
  console.log(result.metadata.creditsAvailable);
  console.log(result.metadata.rateLimitResetTime);
  console.log(result.metadata.rateLimit);
  console.log(result.metadata.rateLimitAvailable);
  console.log(result.metadata.correlationId);

Adjust image

  const result = await imageApi.adjust(
      new AdjustRequest()
        .setImage(imageSource)
        .setBrightness(90)
        .setSharpen(40)
    );
    
  console.log(result.image.url);

Apply effects

  const result = await imageApi.effect(
      new EffectRequest()
        .setImage(imageSource)
        .setEffectName(EffectName.a1972)
    );

  console.log(result.image.url);

Generate background textures

  const result = await imageApi.backgroundTexture(
      new BackgroundTextureRequest()
        .setImage(imageSource)
        .setPattern(TexturePattern.diamond)
        .setHeight(800)
    );

  console.log(result.image.url);

Preview selected effects on an image

  const result = await imageApi.effectPreviews(
      new EffectPreviewsRequest()
        .setImage(imageSource)
        .addEffect(EffectName.a1972)
        .addEffect(EffectName.brnz2)
        .addEffect(EffectName.icy3)
        .addEffect(EffectName.apr3),
    );

  console.log(result.thumbnails);

Enhance face

  const result = await imageApi
  .enhanceFace(
    new EnhanceFaceRequest()
      .setImage(imageSource),
  );

  console.log(result.image.url);

Get balance

  const result = await imageApi.getBalance();
  console.log(result.credits);

Get list of effects

  const result = await imageApi.getEffects();
  console.log(result.effects)

Surface Map

  const result = await imageApi.surfacemap(
      new SurfacemapRequest()
        .setImage(imageSource1)
        .setMask(imageSource2)
        .setSticker(imageSource3)
    );

  console.log(result.image.url);

Text to Image

  const result = await genaiApi.text2Image(
      new Text2ImageRequest()
        .setCount(10)
        .setPrompt("coding all the time")
        .setNegativePrompt("relax and rest")
    );
  console.log(result.images);

Upload Image

  const fileContent = readFileSync("examples/image.png");
  const blob = new Blob([fileContent]);

  const imageSource = ImageApi.fromFile(blob);
  const result = await imageApi.upload(
    new UploadRequest()
      .setImage(imageSource)
  );

  console.log(result.image.url);

Upscale

  const result = await imageApi.upscale(
    new UpscaleRequest()
      .setImage(imageSource)
      .setUpscaleFactor(UpscaleFactor.R2000x2000)
  );

  console.log(result.image.url);

Ultra Enhance

  const result = await imageApi.ultraEnhance(
      new UltraEnhanceRequest()
        .setImage(imageSource)
        .setUpscaleFactor(6),
    );

  console.log(result.image.url);

Ultra Upscale

  const result = await imageApi.ultraUpscale(
      new UltraUpscaleRequest()
        .setImage(imageSource)
        .setUpscaleFactor(4)
        .setMode(ProcessingMode.async),
    );

  console.log(result.image.url);

Build

To build a package use the following command:

npm run build

It will create /lib directory in the root directory of the project which will contain ready to publish npm package.

Adding boilerplate license notice

Run the following command to add the boilerplate license notice in all *.ts files:

npm run license

This command will not only add the header to all new files, but will also fix existing files if there is a need.

To be able to run this on macOS, you need to install GNU sed. If you haven't installed it yet, follow these steps:

  1. Install Homebrew: If you don't have Homebrew installed, open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install GNU sed: Once Homebrew is installed, run the following command to install GNU sed:
brew install gnu-sed

Generating API References

API references are generated using TypeDoc based on TSDoc comments in the code. Run the following command to generate it:

npm run generate-docs

This command will generate API documentation in HTML format in /docs directory.

Tests

To run tests, use the following command:

npm test

License

Picsart Creative APIs SDK is provided under the MIT license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.

This project has some third-party dependencies, each of which may have independent licensing:

How to contribute?

If you like Picsart Creative APIs SDK and would like to contribute to this open-source project, please check the Contribution guide.