ESA Edge Functions let you fetch images, apply transformations with processing parameters on ESA, and cache the results.
Supported operations
Edge Function supports these image transformations:
Parameter | Description |
format | Converts the image format. |
quality | Adjusts the image quality. |
crop | Crops the image to a specified size. |
resize | Resizes the image to specified dimensions. |
rotate | Rotates an image automatically based on its orientation data or clockwise by a specified angle. |
colorGrading | Adjusts the image brightness, contrast, and sharpness. |
waterMark | Adds an image or text watermark. |
info | Retrieves image information, including its dimensions, format, and quality. |
Usage
Transformation structure
All transformation requests use this structure:
image: AnArrayof transformation actions to apply to the fetched image.action: The transformation to perform.option: Configuration for this action.mode: The processing mode. Some actions support multiple modes.param: The processing parameters.
return fetch(imageUrl, {
image: [
{
action: "xxx",
option: {
mode: "xxx",
param: {
},
},
},
{
action: "xxx",
option: {
mode: "xxx",
param: {
},
},
},
],
});
}Format
Example: Convert image format
async function imageFormat() {
return fetch(imageUrl1, {
image: [
{
action: "format",
option: {
param: {
f: "png",
},
},
},
],
});
}No
moderequired for thisaction.Supported types for
param.f
Value:
["jpeg", "png", "webp", "bmp", "gif", "tiff", "jpeg 2000"].Description: Convert image formats.
Quality
Example: Adjust image quality
async function imageQuality() {
return fetch(imageUrl1, {
image: [
{
action: "quality",
option: {
param: {
Q: 5,
},
},
},
],
});
}No
moderequired for thisaction.Supported types for
param.QValue:
0 < Q < 100. Must be a multiple of 5.Description: Adjust image quality.
qValue:
0 < q < 100. Must be a multiple of 5.Description: Adjust image quality.
Crop
Example 1: Circle crop
async function imageCrop() {
return fetch(imageUrl1, {
image: [
{
action: "crop",
option: {
mode: "circle",
param: {
r: 100,
},
},
},
],
});
}Example 2: Centered crop
async function imageCrop() {
return fetch(imageUrl1, {
image: [
{
action: "crop",
option: {
mode: "mid",
param: {
w: 400,
h: 200,
},
},
},
],
});
}This
actionrequires amode. Eachmodesupports differentparamparameters. Image crop. Supportedmodetypes:circle: Circular crop.sudoku: 3x3 grid slicing.coordinate: Specifies clipping by X and Y coordinates.mid: Crops from the center.
circlerorRValid values: An integer greater than
0.Description: Specifies the radius for the circle crop.
sudokugValid values:
["nw", "north", "ne", "west", "center", "east", "sw", "south", "se"]Description: Specifies one of the nine regions of a 3x3 grid.
wValid values:
min: 0max: 16777216Description: Specifies the width of the crop.
hValue range:
min: 0max: 16777216Description: Specifies the height of the crop.
coordinate
xValid values:
min: 0max: 16777216Description: Specifies the X coordinate for the top-left corner of the crop area.
yValid values:
min: 0max: 16777216Description: Specifies the Y coordinate for the top-left corner of the crop area.
wValue range:
min: 0max: 16777216Description: Specifies the width of the crop.
hValid values:
min: 0max: 16777216Description: Specifies the height of the crop.
midwValid values:
min: 0max: 16777216Description: Specifies the width of the crop.
hValid values:
min: 0max: 16777216Description: Specifies the height of the crop.
Rotate
Example 1: Customized rotation
async function imageRotate() {
return fetch(imageUrl1, {
image: [
{
action: "rotate",
option: {
mode: "custom",
param: {
a: 180,
},
},
},
],
});
}Example 2: Automatic rotation
async function imageRotate() {
return fetch(imageUrl1, {
image: [
{
action: "rotate",
option: {
mode: "auto",
param: {
},
},
},
],
});
}This
actionrequires amode. Eachmodesupports differentparamparameters. Image rotation. Supportedmodetypes:custom: Custom rotation.auto: Automatic rotation.
customaorAValid values:
90180270Description: Specifies the clockwise rotation angle in degrees.
auto: Automatic rotation. No parameters are required.
Resize
Example: Custom resize
async function imageResize() {
return fetch(imageUrl1, {
image: [
{
action: "resize",
option: {
mode: "custom",
param: {
p: 90,
// s: 200,
// l: 200,
// w: 200,
// h: 200,
fw: 200,
// fh: 200,
},
},
},
],
});
}actionsupports only thecustommode. Supportedparamparameters:customlswhfwfhValid values:
min: 0max: 16777216Description: Resize images
pValid values:
min: 0max: 100Description: Resize images
Color grading
Example: Adjust image brightness, contrast, and sharpness.
async function imageColorGrading() {
return fetch(imageUrl1, {
image: [
{
action: "colorGrading",
option: {
param: {
b: -100,
c: 10,
s: 50,
},
},
},
],
});
}No
moderequired for thisaction. Supportedparamparameters (Image Color):bValue:
min: -100max: 100Description: Specifies the image brightness.
cValid values:
min: -100max: 100Description: Specifies the image contrast.
sValue:
min: 50max: 399Description: Sets the intensity of the sharpness effect.
Watermark
Example: Add text and image watermarks
async function imageWaterMark() {
return fetch(imageUrl1, {
image: [
{
action: "waterMark",
option: {
mode: "text",
param: {
text: "bW9jaGVuIHRlc3Q",
x: 10,
y: 10,
rotate: 100,
},
},
},
{
action: "waterMark",
option: {
mode: "image",
param: {
image:
"aHR0cHM6Ly9jZG4yLmljb25maW5kZXIuY29tL2RhdGEvaWNvbnMvc29jaWFsLW1lZGlhLTIxODkvNDgvMTMtT3BlcmEtMTI4LnBuZw",
g: 3,
},
},
},
],
});
}