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.
To install the package, run the following command:
npm install --save picsart-creative-apis-ts-sdk
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');
// 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);
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);
const result = await imageApi.adjust(
new AdjustRequest()
.setImage(imageSource)
.setBrightness(90)
.setSharpen(40)
);
console.log(result.image.url);
const result = await imageApi.effect(
new EffectRequest()
.setImage(imageSource)
.setEffectName(EffectName.a1972)
);
console.log(result.image.url);
const result = await imageApi.backgroundTexture(
new BackgroundTextureRequest()
.setImage(imageSource)
.setPattern(TexturePattern.diamond)
.setHeight(800)
);
console.log(result.image.url);
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);
const result = await imageApi
.enhanceFace(
new EnhanceFaceRequest()
.setImage(imageSource),
);
console.log(result.image.url);
const result = await imageApi.getBalance();
console.log(result.credits);
const result = await imageApi.getEffects();
console.log(result.effects)
const result = await imageApi.surfacemap(
new SurfacemapRequest()
.setImage(imageSource1)
.setMask(imageSource2)
.setSticker(imageSource3)
);
console.log(result.image.url);
const result = await genaiApi.text2Image(
new Text2ImageRequest()
.setCount(10)
.setPrompt("coding all the time")
.setNegativePrompt("relax and rest")
);
console.log(result.images);
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);
const result = await imageApi.upscale(
new UpscaleRequest()
.setImage(imageSource)
.setUpscaleFactor(UpscaleFactor.R2000x2000)
);
console.log(result.image.url);
const result = await imageApi.ultraEnhance(
new UltraEnhanceRequest()
.setImage(imageSource)
.setUpscaleFactor(6),
);
console.log(result.image.url);
const result = await imageApi.ultraUpscale(
new UltraUpscaleRequest()
.setImage(imageSource)
.setUpscaleFactor(4)
.setMode(ProcessingMode.async),
);
console.log(result.image.url);
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.
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:
- 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)"
- Install GNU sed: Once Homebrew is installed, run the following command to install GNU sed:
brew install gnu-sed
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.
To run tests, use the following command:
npm test
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:
- axios:^1.7.2, (MIT): Used as a http client
- axios-retry:^4.3.0, (Apache License V2.0): Used as an extension for axios for handling retrying
- form-data:^4.0.0, (MIT): Used for building multipart/form-data payloads
- yup:^1.4.0, (MIT): Used for client side request validations
If you like Picsart Creative APIs SDK and would like to contribute to this open-source project, please check the Contribution guide.