This is the archived documentation for Doka Image Editor v7.
Please visit pqina.nl/pintura/docs/ to see documentation for the latest version of Pintura Image Editor.
Programmatically generating an image
We can use the processImage
function to generate an image without showing or loading the user interface.
Just like with the editor factory methods (openEditor
, appendEditor
, etc) we need to supply the processImage
function with an 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 './doka.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);
});