v8.38.0

Headless image processing

We can use the processDefaultImage function to generate an image without showing or loading the user interface.

import { processDefaultImage } from './pintura.js';

// Create a square crop and scale down image without using the editor UI
processDefaultImage('./my-image.jpeg', {
    imageWriter: {
        targetSize: {
            width: 256,
            height: 256,
        },
    },
    imageCropAspectRatio: 1,
}).then(({ dest }) => {
    // Show resulting image preview
    const preview = new Image();
    preview.src = URL.createObjectURL(dest);
    document.body.appendChild(preview);
});

When using the processImage function we need to supply the imageReader to read image data and an imageWriter to write the output image (if we want to generate an output file).

import {
    processImage,
    createDefaultImageReader,
    createDefaultImageWriter,
} from './pintura.js';

// Create a square crop and scale down image without using the editor UI
processImage('./my-image.jpeg', {
    imageReader: createDefaultImageReader(),
    imageWriter: createDefaultImageWriter({
        targetSize: {
            width: 256,
            height: 256,
        },
    }),
    imageCropAspectRatio: 1,
}).then(({ dest }) => {
    // Show resulting image preview
    const preview = new Image();
    preview.src = URL.createObjectURL(dest);
    document.body.appendChild(preview);
});