Getting started with TypeScript SDK
Begin your journey with the Picsart TypeScript SDK by following this detailed integration guide. Learn how to set up the SDK, create API instances, and manipulate images using various methods such as public URLs, image IDs, local files, and streams. Our comprehensive instructions and code examples will help you efficiently integrate Picsart Creative APIs into your projects. Start enhancing your development workflow today!
Before you start
Check these out before you start
Setting up the API
To begin using the Picsart Creative APIs, you need to install the SDK. Here's a basic setup:
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');
Replace YOUR_API_KEY
with your actual API Key provided by Picsart.
Here’s what each line does:
- Import the Picsart SDK: The
PicsartEnterprise
class from thepicsart-creative-apis-ts-sdk
package is imported. This class provides access to various API functionalities. - Create an Image API Instance:
createImageApi('YOUR_API_KEY')
initializes the API instance for image-related operations. - Create a GenAI API Instance: Similarly,
createGenAIApi('YOUR_API_KEY')
initializes the API instance for generative AI tasks, which can be used for more advanced image manipulation.
Creating an Image Instance
The first step in manipulating an image is to create an Image instance. Picsart provides multiple methods to do this:
const imageSource = imageApi.fromUrl('<https://example.com/image.jpg')>;
const imageSource = imageApi.fromImageId('your-image-id-here');
const fs = require('fs');
const fileContent = fs.readFileSync("examples/image.png");
const imageSource = imageApi.fromFile(fileContent);
const fs = require('fs');
const readStream = fs.createReadStream("examples/image.png");
const imageSource = imageApi.fromStream(readStream);
Once an image instance is created, you can perform various manipulations:
For more examples, check out the TypeScript SDK Repository.
Updated 5 months ago