Imaging : downloading and applying image transformations
- 1 Introduction
- 2 Configuration
- 3 EndPoints
- 4 EndPoint: Transform and download an image
- 4.1 Parameters
- 4.2 Response format
- 4.3 Security
- 4.4 Error codes
- 5 EndPoint: available action list
- 5.1 Parameters
- 5.2 Response format
- 5.3 Security
- 5.4 Error codes
- 6 Command set
- 6.1 Introduction
- 6.2 commenting commands
- 6.3 short syntax versus full syntax
- 6.4 the simplified syntax
- 6.5 values
- 6.5.1 dimension value
- 6.5.2 size value
- 6.5.3 factor value
- 6.5.4 angle value
- 6.5.5 boolean value
- 6.5.6 color value
- 6.5.7 font description
- 6.5.8 text decoration parameter
- 6.5.9 gravity value
- 6.5.10 preset value
- 6.5.11 shade parameters
- 6.5.12 string value
- 6.5.13 text color parameters:
- 6.5.14 fixed size parameter
- 6.5.15 overlay parameter
- 6.5.16 colorization
- 7 commands
- 8 simplified command shortcuts
- 9 Available fill patterns
Introduction
The endpoint of this service allows to download images with some transformations.
Configuration
Each action is associated to an identifier and a JSON configuration.
JSON example
{
"objectname": "name of the object",
"description": "description of action",
"prop": "name of property",
"preset": "name of preset"
"command": { definition of command set }
}Properties and sections
objectname: String - Name of the object (type)
description: String - Short description of action
prop: String - Name of property that contains the file or image
preset: String, optional - Name of the preset
commands: JSON object (or array), optional - A command set (a list of transformation commands). If this property is set, preset property is ignored.
strip: Boolean, default to true. If set, the metadata are removed from the file.
rscname: JSON, optional - The description of name for attachment (see "Download image or file" for details).
11.19 exposeAsPreset: Boolean, default to false. If set, a preset is automatically created using the transform of this action. This feature does’nt work with dynamic (with parameters) transform. The object type, object property and attachment name are not relevant for preset.
11.19 presetSuffix: String - Suffix of preset if exposed. This could be:
a simple extension
Example:
{ "presetSuffix": "png" }the keyword $original to specify the suffix is the original file extension
Example:
{ "presetSuffix": "$original" }an evaluable expression, starting with
eval:. The language is JavaScript. Choose a simple and quick expression to execute. The image file is represented by the variablefileinfos. The type of the evaluated value must be String. The value could be:a simple expression statement. In this case the return could be omitted.
Example:
{ "presetSuffix": "eval:org.apache.commons.io.FilenameUtils.getExtension(fileinfos.getName())=='mp4'?'jpg':'png'" }The body of a slightly more complex function
Example:
{ "presetSuffix": "eval:var extension=org.apache.commons.io.FilenameUtils.getExtension(fileinfos.getName());switch(extension){case'jpg':case'png':return extension;default:return'jpg';}" }if the property is not set, we try to evaluate the extension according to the commands if possible. If the extension is undetermined, a default extension will be selected by the preset process.
11.19 presetName: String - Name of preset. If not set, the name of prefix is the concatenation of preset default prefix (see configuration of plug-in) and action name, normalized to preset name.
11.19 presetDescription: String - Description for preset. If not set, the action description will be used.
11.20 fileFilter: Different types of data - filter for preset. This filter determines if the preset can be built for the presented file.
String. An extension or an evaluable JavaScript expression.
An extension. The preset is built if the extension of the input file is equal to this one.
Example:
{ "fileFilter": "png" }An evaluable JavaScript expression, if string starts with
eval:. The language is JavaScript. Choose a simple and quick expression to execute. The image file is represented by the variablefileinfos. The type of the evaluated value must be boolean. The value could be:a simple expression statement. In this case the return could be omitted.
Example:
{ "fileFilter": "eval:org.apache.commons.io.FilenameUtils.getExtension(fileinfos.getName())=='jpg'" }The body of a slightly more complex function
Example:
{ "fileFilter": "eval:var extension=org.apache.commons.io.FilenameUtils.getExtension(fileinfos.getName());switch(extension){case'jpg':case'png':return true;default:return false;}" }
a String array, as a list of file extensions for which the preset can be built.
Example:
{ "fileFilter": ["png","jpg"] }a JSon Object, as an conditional expression (and combination of all properties)
Property as variable
extension: extension of file
mimetype: mimetype of file
name:name of file
basename:name of file (without extension)
path: relative to san path of the file
length: length of file (bytes)
lastmodified: last modified timestamp (unix epoch time)
Value is the test to be performed, as
a simple value. To check if the variable is equal to the value
Example:
{ "fileFilter": { "extension":"jpg" } }an object, and combination of all properties, where name is an operator and value, the value to be used with the operator, or an array of values (combined with an or)
eq or
=: testing for equalityne or
!=: testing for differencegt or
>: testing for greater thangte or
>=: testing for greater than or equalslt or
<: testing for lower thanlte or
⇐: testing for lower than or equalssw or
startswith: testing for lower thanew or
endswith: testing for lower than or equalse or
empty: testing for is emptyct or
contains: testing for containsmt or
matches: testing for regular expression (java)
an array. or combination of all items
Example 1:
{ "fileFilter": { "extension":["jpg","png"] } }Example 2:
{ "filter": { "mimetype":["application/pdf",{"startswith":"image/"}] } }
Property as logical operator.
or The value must be an array of conditions.
Example:
{ "fileFilter": { "or": [ {"path": {"ct":"/asset/"}}, {"path": {"ct":"/legacy/"}} ] ] } }and The value must be an array of conditions.
Example:
{ "fileFilter": { "and": [ {"extension":"jpg"}, {"length":{"<":"2MiB"}} ] ] } }not The value must be an object
Example:
{ "fileFilter": { "not": { "extension": ["zip","mp4"] ] } } }
an array, as a combination table of the above types
Example:
{ "fileFilter": [ { "extension":"jpg" }, { "extension":"png", "length":{"<":"2MiB"} } ] }
EndPoints
There are two endpoints available:
To download a file
To get a list of available actions
EndPoint: Transform and download an image
No parameter endpoints: 11.12
GET http://host:port/app/media/{actionName}/{id}{/transform}GET http://host:port/app/rest/media/{actionName}/{id}{/transform}
11.14
GET http://host:port/app/api/json/imaging/{actionName}/{id}{/transform}11.12
GET http://host:port/app/api/json/imagingLegacy endpoint:
http://host:port/app/_plugins/WXM_RESTAPI/page/imaging.jspzSupported methods: GET, HEAD
Parameters
actionName: String - Action identifier
id (or form_id): Object identifier (mandatory)
commands: String, or JSON, optional - A preset or a command set, to replace the default configured one. If the parameter contains a simple String, it is considered as a preset name, and if it contains JSON, it is considered as command set.
transform: String, optional - A command set using simplified syntax.
11.13 attachment: boolean, optional (default is true): specify if the Content-Disposition header is set (with filename) or not
Response format
The transformed image is returned in the body, as attachment. The response contains the following specific header:
Content-ID: the ID of the content. The form of the content ID is <the name of the view>.
Security
The imageprocessing action of the RESTAPI domain allows the management of endpoint call authorisation. Its unique parameter is actionName, the action identifier.
Error codes
HTTP Code | API Code | Definition |
|---|---|---|
404 | 404/1100 | Unknown action |
403 | 403/1100 | Unreachable action (or forbidden) |
422 | 422/1100 | Unreachable action (configuration problem) |
422 | 422/1101 | Resource not found |
403 | 403/1102 | Forbidden action |
500 | 500/1100 | Internal server error (error with command, preset or image file…) |
EndPoint: available action list
11.12
GET http://host:port/app/api/json/catalog/imagingLegacy endpoint:
http//host:port/app/_plugins/WXM_RESTAPI/page/catalog/imaging.jspzSupported methods: GET, HEAD
Parameters
actionName: Character string, an optional Regular Expression type filter (by default, all accessible actions are displayed)
Response format
{
"catalog": "list of image processing actions",
"response": {
"data": [ {
"name": "name of the action",
"description": "description of the action",
"preset": "name of preset"
"command": { description of command }
}
}
]
},
"links": {
"href": "http://host:port/app/_plugins/WXM_RESTAPI/page/catalog/imaging.jspz"
},
"status": 200,
"time": 29
}Security
The catalog action of RESTAPI domain allows the management of the endpoint call authorisation. Its unique parameter is endPoint, with a imageprocessing value.
Error codes
HTTP Code | API Code | Definition |
|---|---|---|
403 | 403/601 | Unreachable catalog (or forbidden) |
Command set
Introduction
A command set is a list of commands that will be executed one after the other on the image. There are three different forms of syntaxes:
simplified: this syntax could be used within the transform parameter. The syntax is very simplified but not all options are available
short syntax: this syntax use arrays to shorten commands and the parameters aren’t explicitely named. This syntax is less flexible than the full syntax
full syntax: this syntax use object to configure each command and all options are available with it.
A command set can be configured as an object, where each property is a command name. As the JSON syntax doesn’t allows to have several properties with the same name, you can use an array of objects (JSON object with command property, JSON array with command name as first item, or object with a single property) .
Example of object command set:
{
"resize": [100,-1],
"format": "png"
}Example of array command set:
[
{
"command":"crop",
"width":100
},
["preset","identifierOfPreset"],
{
"resize": {"width":"50%","height":"50%"}
}
]commenting commands
A command can be temporarily disabled by commenting its name: just prefix the name with the dollar character ($).
{
"resize": [100,-1],
"$format_cpl20180812": "jpg",
"format": "png"
}To comment a command in simplified syntax, take care to put the $ at the beginning of the name of command, not before the prefix, like this by example: w_100,h_100,c_resize,e_png,c_$format. The command and all its parameters are skipped in that case.
short syntax versus full syntax
Example of shorten syntax (array) command:
"resize": [100,-1],Example of full syntax command:
"resize": {
"width":100,
"height":"proportional"
}The array syntax is shorter, but you’ll have to care of the order of parameters, and sometimes some ambiguities will force you to use the full syntax. Note that full syntax allows some default values for missing parameters that cannot be handled in short syntax.
the simplified syntax
This syntax does not use JSON syntax. The command set is defined by a comma separated list of parameters:
a prefix (one or two letters) followed by an underscore then by a value. The prefix defines the type of value:
c for a command name
w for width
h for height
etc
a name without underscore possibly prefixed by a
+or a-
by example:+fixed
This kind of parameters are boolean switches. By default, the value is true. The prefix - set it to false and the prefix + explicitly set it to true.
Each command is preceded by its parameters.
Example:
w_100,h_100,c_resizeSimple text (without spaces or special characters) can be specify also:
tx_helloTo specify text with spaces, or other special characters, embrace it between double-quotes:
tx_"hello you!"You can put double-quotes within text by duplicate them:
tx_"say ""hello""!"Use antislash \ to escape special characters, like \n for carriage return. Use two of them to get an antislash: \\n means exactly \n, not carriage return.
tx_"First line\nSecond line: \\n"(the text will be:
first line
second line: \n)
You can use \u followed by unicode codepoint (four hexadecimal digits mandatory) to specify special characters:
tx_"\u00a9xxx"(the text will be: ©xxx)
Spaces are not allowed in shorten syntax, except within texts.
values
Except for switches, the values for the parameters are the same for all syntaxes. For switches, in full syntax, use the values true or false, and in short syntax, only the name of the switch.
By example, these three syntaxes mean the same:
t_10%,+fixed,c_crop"crop": ["fixed","10%"]"crop": {
"fixed":true,
"top":"10%"
}dimension value
Defines a dimension (x, y, width, height, top, right, bottom or left) in pixels. It could be absolute or relative to the size of the image.
a positive number means an absolute size in pixels
"width": "100", "height": 100a positive number followed by
pxmeans an absolute size in pixels"width": "100px", "height": "100 px"a positive number followed by
f(or×) means a factor"width": "2f", "height": "0.5f"means doubled width and halved height.
a number followed by
%(orp) means a percentage"width": "200%", "height": "50p"the word proportional could be used as value in some commands (you can use also the number
-1)
size value
Defines a dimension in different units. The same values as used for dimension value could be used, and the followed additional syntaxes:
a number followed by mm means a size in millimeters.
"width": "50mm"a number followed by a quote means a size in inches.
"width": "50'"a number followed by
ptmeans a size in points."width": "72pt"
factor value
Defines a factor.
a positive number means a factor: the final size will be the original size multiplied by the factor
"width": "2", "height": 0.5means doubled width and halved height.
a number followed by
f(or×) means a factor"width": "2f", "height": "0.5×"means doubled width and halved height.
a number followed by
%(orp) means a percentage"width": "200%", "height": "50p"
angle value
Defines an angle value, in degrees by default.
a number means a value in degrees
"rotate": -45a number followed by
°ordegmeans an angle in degrees:"rotate": "45°""rotate": "60deg""rotate": "-120 deg"a number followed by
radmeans an angle in radians:"rotate": "3.14rad"a number followed by
pi, (or%orπ) means pi multiplied by the value:"rotate": "1.5pi"means 3⁄2 × π
an integer followed by
>, (or "right") means a clockwise 90 degrees rotation (number 1 may be omitted):"rotate": "2>""rotate": "right"an integer followed by
<, (or "left") means a counterclockwise 90 degrees rotation (number 1 may be omitted):"rotate": "left""rotate": "2left"
boolean value
Defines a boolean. Value can be true or false (JSON boolean or string).
"fixed": true,
"centered": "false"color value
Defines a color, with
html color name
"color": "red"gray level
"color": "gray50"hexadecimal RGB code
"color": "#FF0000"word none, for transparent color
"color": "none"an array of RGB (three components for red, green and blue, between
0and255included) or RGBA (four components adding alpha component to RGB components, between0.0and1.0included or"0"and"100%") components"color": [255,0,0]"color": [255,0,0,"50%"]"color": [255,0,0,0.5]a string starting with $dom to specify the dominant color of the image. It can be followed with the index of the dominant color.
$dom means the first dominant color
$dom2 means the second dominant color
$dom2-1 means the second dominant color, skipping the first one
"color": "$dom"
a string starting with
$gradient:, followed with the starting and the ending colors, separated by a dash, to specified a vertical gradient."color": "$gradient:red-blue"You can specify an extent with a dimension value:
"color": "$gradient:red-blue-50%"No color value means none:
"color": "$gradient:red"is equivalent to
"color": "$gradient:red-none"a string starting with
$pattern:, followed with the name of a pattern, to specified a pattern."color": "$pattern:checkerboard"2021.6 The name of the pattern could be followed by a scaling factor, separated with an asterisk. Example :
$pattern:checkerboard*5(multiply size by 5).
See list of Available fill patterns below.the string
$blur, or a string starting with$blur:followed with blur parameters, to specify a blur of the background image.blur parameters: It’s two positive integers separated with an
x. The first is radius and the second sigma."color": "$blur:25x25"$blur is equivalent to $blur:3x3
font description
Defines a font, with a font name (a string), a font size (cf "size value"), font styles (bold, italic…).
a string, with component separated with a pipe
"font": "Arial""font": "Arial|16pt""font": "Candice|20%|bold"