To assist with the usage of this Extension, a utility library exists to help provide a typed API interface for easily constructing operations to send to the API.
npm i --save @invertase/image-processing-apiOnce installed, import the builder function from the library:
import { builder } from '@invertase/image-processing-api';The builder function returns a new ImageProcessingApi instance which provides a API for constructing operations to send to the API.
At a minimum, you must provide an input and output operation as required by the extension itself:
import { builder } from '@invertase/image-processing-api';
const build = builder()
.input({
url: 'https://example.com/image.jpg',
})
.output({
format: 'png',
});To provide additional operations, you can chain them together. For example, to apply a blur, grayscale and flip the provided input image, and return a new PNG image:
const output = builder()
.input({
url: 'https://example.com/image.jpg',
})
.blur()
.grayscale()
.flip()
.output({
format: 'png',
});Please refer to the operations documentation for a full list of available operations, their API and examples.
Once you have constructed your operations, you can return the operations as JSON, a JSON string or encoded JSON string value:
const json = output.toJSON();
const jsonString = output.toJSONString();
const encodedJsonString = output.toEncodedJSONString();The encoded JSON string value can be passed directly to the extension as the operations parameter:
const encodedJsonString = output.toEncodedJSONString();
const url = `https://{LOCATION}-{PROJECT_ID}.cloudfunctions.net/ext-image-processing-api-handler/process?operations=${encodedJsonString}`;