Setting up Pintura Image Editor with Svelte

For a quick start use the Svelte example project included in the product package as a guideline. It includes a normal, modal, and overlay editor example.

We can install pintura and svelte-pintura with npm by copying both of the dependencies to the 'local_modules' folder in root of our Svelte project and running the following command to install them locally.

npm install --save ./local_modules/svelte-pintura ./local_modules/pintura

Now we can import the modules like we normally would and use the Svelte <PinturaEditor>, <PinturaEditorModal>, and <PinturaEditorOverlay> components.

Events and properties

To listen for events we can use the on: attribute.

<PinturaEditor on:load={handleEvent}></PinturaEditor>

Properties names are set the same way as in the JavaScript version of the editor.

<PinturaEditor src="image.jpeg" imageCropAspectRatio={1}></PinturaEditor>

Default implementation example

In the default example below we'll use the getEditorDefaults method to quickly create an image editor.

This creates a "default" editor that has all available plugins loaded and comes preset with all plugin default options and English locale. Each of these settings can be adjusted freely.

    // Import from `pintura`
    import 'pintura/pintura.css';

    // Import the editor default configuration
    import { getEditorDefaults } from 'pintura';

    // Import from `svelte-pintura`
    import { PinturaEditor } from 'svelte-pintura';

<div style="height:600px">

Advanced implementation example

In this example we'll create a custom editor, using a custom set of plugins, locale, and available options.

While this example is a lot more verbose it does allow us to create a more optimal editor package. The build process will tree-shake unused functionality resulting in a smaller build target.

// Import from `pintura`
import 'pintura/pintura.css';

// Import the editor functionality
import {
    // Import the default image reader and writer

    // The method used to register the plugins

    // The plugins we want to use

    // The user interface and plugin locale objects

    // Because we use the annotate plugin we also need
    // to import the markup editor locale and the shape preprocessor

    // Import the default configuration for the markup editor and finetune plugins
} from 'pintura';

// Import from `svelte-pintura`
import { PinturaEditor } from 'svelte-pintura';

// This registers the plugins with Pintura Image Editor
setPlugins(plugin_crop, plugin_finetune, plugin_filter);

// Create our editor configuration
const editorConfig = {
    // This will read the image data (required)
    imageReader: createDefaultImageReader(),

    // This will write the output image
    imageWriter: createDefaultImageWriter(),

    // The markup editor default options, tools, shape style controls

    // The finetune util controls

    // This handles complex shapes like arrows / frames
    shapePreprocessor: createDefaultShapePreprocessor(),

    // This will set a square crop aspect ratio
    imageCropAspectRatio: 1,

    // The icons and labels to use in the user interface (required)
    locale: {

<div style="height:600px">

Next steps

With the editor set up, we can continue to configure the editor to our liking by adjusting the available configuration options