Endpoints
https://api.nicelink.xyz/sharp
The /jimp endpoint is now an alias of /sharp, but might be removed in favour of /sharp.
sharp.js is the library used for image manipulation. In general the features supported by Sharp.js are supported by this API.
Get an image
Get image
curl -X get \
https://api.nicelink.xyz/sharp/transparent.png
{output;
{file;buffer:{jget;{request;https://api.nicelink.xyz/sharp/transparent.png};body}};transparent.png}
}
{//;More likely would be to just display the URL}
https://api.nicelink.xyz/sharp/transparent.png
Response (Image Buffer)
GET https://api.nicelink.xyz/sharp/:imageName
Any image stored can be retrieved by using the name of the image provided by an endpoint like /store.
Analyze image
Example request
curl -X POST -H "Content-Type: application/json" \
-d '{"background": "https://example.com/image.png"}' \
https://api.nicelink.xyz/sharp
{set;~payload;{json;{
"background": "https://example.com/image.png"
}}}
{jget;{request;https://api.nicelink.xyz/sharp;{jset;;method;POST};{get;~payload}};body}
JSON response:
{
"errors" : ["Invalid background image"],
"warnings" : [],
"children" : []
}
POST https://api.nicelink.xyz/jimp
Request body is an ImageObject
Generate image
Example request
curl -X POST -H "Content-Type: application/json" \
-d {"background": "https://api.nicelink.xyz/sharp/transparent.png", "text": [{"text": "Hello world!"}], "crop": "auto"} \
https://api.nicelink.xyz/sharp/process
{set;~json;{json;{
"background": "https://api.nicelink.xyz/sharp/transparent.png",
"text": [
{
"text": "Hello world!"
}
],
"crop": "auto"
}}}
{set;~response;{request;https://api.nicelink.xyz/sharp/store;{jset;;method;POST};{get;~json}}}
{file;buffer:{jget;~response;body};image.png}
Returns an image
POST https://api.nicelink.xyz/sharp/process
Request body must be an ImageObject
This endpoints directly returns the generated image
Store image
Example request
curl -X POST -H {"Content-Type: application/json"} \
-d {"background": "https://api.nicelink.xyz/sharp/transparent.png", "cacheDuration": 7, "text": [{"text": "Hello world!"}], "crop": "auto"} \
https://api.nicelink.xyz/sharp/store
{set;~json;{json;{
"background": "https://api.nicelink.xyz/sharp/transparent.png",
"cacheDuration": 7,
"text": [
{
"text": "Hello world!"
}
],
"crop": "auto"
}}}
{set;~response;{request;https://api.nicelink.xyz/sharp/store;{jset;;method;POST};{get;~json}}}
{jget;~response;body}
JSON Response:
{
"root" : "https://api.nicelink.xyz/sharp/",
"path" : "d7596506-9ee8-4a42-8cea-b51670378920.png",
"url" : "https://api.nicelink.xyz/sharp/d7596506-9ee8-4a42-8cea-b51670378920.png",
"errors" : [],
"warnings" : [],
"children" : []
}
POST https://api.nicelink.xyz/sharp/store
Request body must be an ImageObject
This endpoint allows you to store an image for a determined amount of time (cacheDuration). GETting an image extends the duration it's stored for by cacheDuration.
After cacheDuration days have passed since the last access the image will be deleted. GETting the image after this will re-generate the image and re-store it. 90 days after its last access the image will be permanently gone.
Input Bodies
Image Object
Example actions:
Replacing a colour:
{
"bg": "https://api.nicelink.xyz/docs/images/logo.png",
"replaceColor": {
"target" : "#000000",
"replace" : "#00FF00",
"delta" : 50
}
}
Hello world:
{
"text": [
{
"text": "Hello world!"
}
],
"crop": "auto"
}
Add some eyes to the logo:
{
"bg": "https://api.nicelink.xyz/docs/images/logo.png",
"images": [
{
"bg": "https://api.nicelink.xyz/sharp/edcd1b62-911a-4b5b-804a-a82d72b90060.png",
"align": "center",
"x": -125,
"y": -50,
"width": 100
},
{
"bg": "https://api.nicelink.xyz/sharp/edcd1b62-911a-4b5b-804a-a82d72b90060.png",
"align": "center",
"x": 125,
"y": -50,
"width": 100
}
]
}
| Property | Alias | Type | Default | Description |
|---|---|---|---|---|
| background | bg | string |
transparent.png | URL of the background to use. |
| cacheDuration | number |
7 |
When using the /store endpoint this will determine the amount of days the image is stored for. Maximum of 30 days. |
|
| width | w | number |
Original width | Width of the image. |
| height | h | number |
Original height | Height of the image. |
| opacity | o | number |
100 |
Opacity of the image ranging from 0-100 |
| rotate | r | number |
0 |
Clockwise rotation of the image in degrees. |
| shape | s | string |
undefined |
Shape of the image. Can be circle. |
| flip | number |
undefined |
Flips the image horizontally or vertically. Accepted values are 1 (horizontal flip), 2 (vertical flip) and 3 (horizontal + vertical flip) |
|
| images | children | ChildObject[] |
[] |
Array with ChildObjects. |
| text | txt | TextObject|TextObject[] |
undefined |
Renders text on the image |
| crop | CropObject|number|"auto" |
undefined |
Crops the image based on the parameters provided. Argument can be a number in which case it will crop from x = 0 and y = 0 until x = number and y = number. Or the argument can be a CropObject or "auto" which trims the transparent region around the image. |
|
| replacecolor | ReplaceColorObject |
undefined |
Replaces a certain colour with another colour |
Child Object
Example action:
Creating a triangle shape
{
"bg": "https://api.nicelink.xyz/docs/images/logo.png",
"images": [
{
"bg": "https://api.nicelink.xyz/sharp/958d2e27-2c35-421b-8643-03b237e428c1.png",
"rotate": 180,
"align": "center",
"y": 50,
"blendMode": "dstIn",
"size": "contain"
}
]
}
A ChildObject supports all the properties of InputBody, in addition to the following properties:
| Property | Alias | Type | Default | Description |
|---|---|---|---|---|
| x | number |
0 |
Horizontal position of the image on the parent image. | |
| y | number |
0 |
Vertical position of the image on the parent image. | |
| alignment | align | string |
undefined |
Alignment of the image on the parent image. Can be any of the modes listed under "Supported alignment modes". If this property is provided in combination with x and/or y, x and y will be the offset. |
| size | string |
undefined |
Can be contain. contain scales the child image down so it fits inside the parent element. |
|
| blendMode | string |
srcOver |
Blend mode to use when composting the child image on the parent image. A list of blend modes can be found below under Blend modes |
Text Object
Example actions:
Hello world
{
"text": [
{
"text": "Hello world!",
"color": "white",
"size": "100px"
}
],
"crop": "auto"
}
Hello world, but with a cool font
{
"text": [
{
"text": "Hello world!",
"font": "DS Uncial Funny Hand",
"color": "white",
"size": "100px"
}
],
"crop": "auto"
}
Hello world in a box
{
"text": [
{
"text": "Hello world!",
"color": "white",
"size": "100px",
"borderWidth": 10,
"padding": 5,
"borderColor": "green"
}
],
"crop": "auto"
}
Hello world, yellow background
{
"text": [
{
"text": "Hello world!",
"color": "black",
"size": "100px",
"bgColor": "yellow",
"padding": 5
}
],
"crop": "auto"
}
| Property | Alias | Type | Default | Description |
|---|---|---|---|---|
| x | number |
0 |
x coordinate/offset of the text block. | |
| y | number |
0 |
y coordinate/offset of the text block. | |
| align | string |
top-left |
Alignment mode of the text block. Alignment modes can be seen in the Supported alignment modes section | |
| size | number |
30 |
Pixel size of the text. | |
| font | FONTSTYLE |
sans-serif |
Supported fonts are listed at /sharp/fonts. Each support font family has an array of supported font styles. | |
| textAlign | string |
left |
Alignment mode of the text inside the text block. This is not the same as the align property. |
|
| textColor | color | string |
black |
Color of the text. |
| backgroundColor | bgColor | string |
transparent |
Color of the background. |
| lineSpacing | number |
0 |
Amount of spacing between lines. | |
| maxWidth | number |
width of parent - x |
Max width of the text block. Defaults to the width of the parent image minus the x offset. |
|
| strokeWidth | number |
0 |
Width of the text stroke in pixels. | |
| strokeColor | string |
white |
Color of the text stroke. | |
| When using a stroke, the padding might need to be increased to avoid cutting off. | ||||
padding{Side} |
padding | number |
0 |
Padding in pixels on {Side}, where {Side} can be Left, Right, Top, Bottom or nothing for all sides |
padding property is only used for a side if the side-specific property is not provided. |
||||
border{Side}Width |
borderWidth | number |
0 |
Width of the border on {Side}. Uses same logic as padding{Side} |
| borderColor | string |
black |
Color of the border. |
Crop Object
Example Object
{
"x": 30,
"y": 12,
"w": 1000
}
| Property | Type | Default | Description |
|---|---|---|---|
| x | number |
0 |
X position to start the crop at |
| y | number |
0 |
Y position to start the crop at |
| w | number |
Image width |
The width of the crop region |
| h | number |
Image height |
The height of the crop region |
Replace Color Object
Example Object
{
"target": "#FF0000",
"replace": "#00FF00"
}
| Property | Type | Default | Description |
|---|---|---|---|
| target | string |
Target hex colour | |
| replace | string |
Replacement hex colour | |
| delta | number |
2.3 |
The deltaE value to use, more info here |
Supported alignment modes
| top-left | top-middle | top-right |
| left | center | right |
| bot-left | bot-middle | bot-right |
Blend modes
For more information about the blend modes visit libvips blendmode and cairographics compositing operators
Supported modes are: srcOver, srcIn, srcOut, srcAtop, dstIn, dstOut, dstAtop, dstOver, hardLight, softLight, colourDodge, colourBurn, add, screen, overlay, lighten, darken, multiply, difference, exclusion, clear, source, saturate, xor and dest