v8.89.8

Filter plugin

The Filter plugin enables applying color matrix filters to the preview image.

We can import the default filter set or define our own filters.

Property Default value Description
filterFunctions
undefined
An object with color matrices describing the various filters shown in the filter menu.
filterOptions
undefined
A list of key label pairs describing which finetune controls to render.

filterFunctions

An object with color matrices describing the various filters shown in the filter menu.

The key pastel matches the pastel key used in the filterOptions array, that's how Pintura Image Editor determines which control to render for each button.

<!DOCTYPE html>

<head>
    <link rel="stylesheet" href="./pintura.css" />
</head>

<style>
    .pintura-editor {
        height: 600px;
    }
</style>

<div id="editor"></div>

<script type="module">
    import {
        appendDefaultEditor,
        filterInvert,
        plugin_filter,
        plugin_filter_defaults,
    } from './pintura.js';

    const editor = appendDefaultEditor('#editor', {
        src: 'image.jpeg',
        filterFunctions: {
            // the default filter functions
            ...plugin_filter_defaults.filterFunctions,

            // add the invert filter (not included in plugin_filter_defaults.filterFunctions)
            invert: filterInvert,

            // add a custom filter
            blue: () => {
                // prettier-ignore
                return [
                    0,  0,  0,  0, 0,
                    0,  0,  0,  0, 0,
                    1,  1,  1,  0, 0,
                    0,  0,  0,  1, 0
                ]
            },
        },
        filterOptions: [
            ...plugin_filter_defaults.filterOptions,
            ['Custom', [['blue', 'Blue']]],
        ],
    });
</script>

The utility below helps us generate our own photo filters.

  • Drop an image file on the picture to load a different image.
  • Hold Shift to select multiple fields at once clicking or dragging.
  • Click "copy" to copy the current Color Matrix to your clipboard.

filterOptions

A list of key label pairs describing which finetune controls to render. Label can be a string but in most cases is a function, the function is then passed the current locale and can select the correct locale key.

<!DOCTYPE html>

<head>
    <link rel="stylesheet" href="./pintura.css" />
</head>

<style>
    .pintura-editor {
        height: 600px;
    }
</style>

<div id="editor"></div>

<script type="module">
    import { appendDefaultEditor } from './pintura.js';

    const editor = appendDefaultEditor('#editor', {
        src: 'image.jpeg',
        filterOptions: [
            ['Default', [[undefined, (locale) => locale.labelDefault]]],
            [
                'Classic',
                [
                    ['chrome', (locale) => locale.filterLabelChrome],
                    ['fade', (locale) => locale.filterLabelFade],
                    ['pastel', (locale) => locale.filterLabelPastel],
                    ['cold', (locale) => locale.filterLabelCold],
                    ['warm', (locale) => locale.filterLabelWarm],
                ],
            ],
            [
                'Monochrome',
                [
                    ['monoDefault', (locale) => locale.filterLabelMonoDefault],
                    ['monoNoir', (locale) => locale.filterLabelMonoNoir],
                    ['monoWash', (locale) => locale.filterLabelMonoWash],
                    ['monoStark', (locale) => locale.filterLabelMonoStark],
                ],
            ],
            [
                'Sepia',
                [
                    [
                        'sepiaDefault',
                        (locale) => locale.filterLabelSepiaDefault,
                    ],
                    ['sepiaRust', (locale) => locale.filterLabelSepiaRust],
                    ['sepiaBlues', (locale) => locale.filterLabelSepiaBlues],
                    ['sepiaColor', (locale) => locale.filterLabelSepiaColor],
                ],
            ],
        ],
    });
</script>

Filter plugin exports

The core editor module exports the following Filter plugin objects.

Export Description
plugin_filter The filter util view.
plugin_filter_defaults A default filter util configuration object exposing a selection of the filters below.
plugin_filter_locale_en_gb The filter util locales.
filterPastel The Pastel filter.
filterChrome The Chrome filter.
filterFade The Fade filter.
filterWarm The Warm filter.
filterCold The Cold filter.
filterInvert The Invert filter.
filterMonoDefault The Mono default filter.
filterMonoNoir The Mono Noir filter.
filterMonoWash The Mono Wash filter.
filterMonoStark The Mono Stark filter.
filterSepiaDefault The Sepia default filter.
filterSepiaBlues The Sepia Blues filter.
filterSepiaRust The Sepia Rust filter.
filterSepiaColor The Sepia Color filter.