How to setup for the Basic plan

This is a quickstart guide on setting up the Basic Plan for the Photo and Video Editor SDK. This guide will walk you through the essential steps to get started with simple photo editing, providing a straightforward approach suitable for beginners. Whether you're setting up for personal use or integrating it into your platform, follow along to enable basic photo editing capabilities with ease.

In this page we will see how Photo and Video Editor SDK can be setup for the basic plan.

Before we go forward, let's quickly go over the differences between the basic and configurable plans.

The highlight is that the basic plan is designed for an easy start and simple photo editing experiences. In contrary, the configurable package allows for more advanced configuration options, in particular, you can set it up for video editing or print design and can control almost all features.

Let's now get back to the simple photo editing use case. As it was shown in the quickstart it's required to have an HTML host page, a place to embed the editor. The container of the editor can, in general, be any block element. Here we use <div> as an example:

<div id="photoEditorContainer" style="width:768px; height:350px;"></div>

Be wary of the minimal space required to visualize the editor properly.

Let's now build our editor step by step.

Step 1 - Load the editor and set the access up

We need to load the SDK

<div id="photoEditorContainer" style="width:768px; height:350px;"></div>
<script src="https://sdk.picsart.io/cdn?v=1.8&key=sdk"></script>

and initialize the editor

const PicsartInstance = new Picsart({
      propertyId: 'yourdomainaddress.com', // example: 'picsart.com'
      containerId: 'photoEditorContainer',
      apiKey: 'Your API Key here',
      mode: 'photo',
      ...
});

It's important to set these three up properly.

  1. The propertyID is your production domain address.
  2. The apiKey is your API access key. It's not always required. For instance, it will be mandatory in case the Remove Background feature is enabled.
  3. The containerId should match the value of the id attribute of the container element.

Step 2 - Open the editor

Opening the editor means rendering it on the page. Unless it's performed, the container will look empty.

PicsartInstance.open({ 
      selectedTool: 'uploads',
      title: 'Picsart Editor'
});

The title value allows to customize the name of the editor, having your use case and business flow. You're free to give it any name, e.g. Photo editor or Card designer, etc.

The selectedTool is not mandatory, but we recommend to use it to be confident in what will load. The tools available for selection are

  • upload
  • text
  • elements
  • background

Step 3 - Control your features

Now that we have the editor's basic setup, let's also have a little extra control over what shows up on your screens.

const PicsartInstance = new Picsart({
      mode: 'photo',
      theme: 'light', // turns the color mode of the UI into lighter colors,
      features: {
        undoRedoControls: true,
        zoomControls: true,
        tools: [
            'edit',
            'color',
            'gradient',
            'eraser',
            'duplicate',
            'adjust',
            'font',
            'border',
            'outline',
            'shadow',
            'flip_rotate',
            'position',
            'tool_removeBG'
          ],
      },
      categories: {
        text: {
          title: true,
        },
        uploads: {
          title: true,
          tabs: ['Images'],
        },
        elements: {
          smallTitle: true,
        },
        background: {
          header: true,
          tabs: ['Color', 'Upload']
        },
      },
});

The features>tools configuration allows to control photo editing features. For example, you can decide whether basic editing like opacity and bland should be enabled or not, etc.

Pay extra attention to the tool_removeBG. This one enables the remove background feature on photos and it implies remove background API usage. This requires the apiKey be provided. Every time remove background is performed, it will make a call to the API service and consume credits.

Make sure to purchase enough credits to ensure an uninterrupted remove background processing. See the pricing for remove background.

The categories section in this configuration controls what you see on the left side of the editor. This includes the option to upload images and add to the design, add text, elements/shapes as well as the ability to modify the background.

In the background section you can choose whether the user can add color and/or upload and apply a photo.

Step 4 - Control what to export, handle the result

Now, let's see how we can control what files should be exported. The full list of export formats can be found here and here we will show how to export in JPEG.

const PicsartInstance = new Picsart({
      ...
      exportFormats: ['image/jpeg'],
      ...
});

And there are options to choose from, what to expect, a blob, base64 or buffer (read more about all export types here).

const PicsartInstance = new Picsart({
      ...
      exportType: 'blob',
      ...
});

PicsartInstance.onExport((output) => {
      PicsartInstance.close();
      if (output.data.imageData) downloadFile(output.data.imageData, 'image.jpeg');
});

Step 5 - Two more little things

Almost there, let's also see how you should provide the list of shapes as well as hot to control the label on the next button.

PicsartInstance.provideShapes({ dataURL: 'https://cdn140.picsart.com/41273773997815915185.json' });

PicsartInstance.provideLabels({
      nextButton: 'Export',
});

Summary

As we have gone through the whole setup process, let's see how the final HTML file should look like.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>[Your company name]</title>
</head>

<body>
  <style>
    body {
      padding: 100px;
      font-family: Helvetica, Arial, sans-serif;
    }

    .container {
      position: absolute;
      top: 20px;
      left: 20px;
      right: 20px;
      bottom: 20px;
      pointer-events: none;
    }

    iframe {
      border: none;
      border-radius: 4px;
      box-shadow: 1px 1px 20px rgba(0, 0, 0, 0.4);
      border-radius: 4px;
    }
  </style>
  <div id="containerId" class="container"></div>
  <script src="https://sdk.picsart.io/cdn?v=1.8&key=sdk"></script>
  <script>
    const downloadFile = (blob, fileName) => {
      const link = document.createElement('a');
      link.href = URL.createObjectURL(blob);
      link.download = fileName;
      document.body.append(link);
      link.click();
      link.remove();
    };

    const PicsartInstance = new Picsart({
      propertyId: 'yourdomainaddress.com', // example: 'picsart.com'
      containerId: 'containerId',
      apiKey: 'Your API Key here',
      exportFormats: ['image/jpeg'],
      exportType: 'blob',
      mode: 'photo',
      theme: 'light', // turns the color mode of the UI into lighter colors,
      features: {
        undoRedoControls: true,
        zoomControls: true,
        tools: [
            'edit',
            'color',
            'gradient',
            'eraser',
            'duplicate',
            'adjust',
            'font',
            'border',
            'outline',
            'shadow',
            'flip_rotate',
            'position',
            'tool_removeBG'
          ],
      },
      categories: {
        text: {
          title: true,
        },
        uploads: {
          title: true,
          tabs: ['Images'],
        },
        elements: {
          smallTitle: true,
        },
        background: {
          header: true,
          tabs: ['Color', 'Upload']
        },
      },
    });

    PicsartInstance.provideShapes({ dataURL: 'https://cdn140.picsart.com/41273773997815915185.json' });
    PicsartInstance.provideLabels({
      nextButton: 'Export',
    });

    PicsartInstance.onExport((output) => {
      PicsartInstance.close();
      if (output.data.imageData) downloadFile(output.data.imageData, 'image.jpeg');
    });

    PicsartInstance.open({ 
      selectedTool: 'uploads',
      title: 'Picsart Editor'
    });

  </script>
</body>

</html>

After all, you can simply save this code to your local drive and open the HTML file to get how things come together.

Should you have any issue or any question in regards to this setup process, we would be happy to hear your feedback. Don't hesitate to contact us.