Batch Image Processing
Your First Batch Request

For this tutorial we'll be using Postman. You'll also need a Batch Service already setup.
Don't have a Batch Service yet? Click Here!

There are a few requirements in order to make your first batch request, these are:

  1. Service ID: This can be found inside your service page on the SlashedCloud dashboard.
  2. Service Secret Key: This can be found inside your service page on the SlashedCloud dashboard.
  3. API Endpoint: https://batch.slashed.cloud
  4. Source: The path of your image source.
  5. Destination: The path of your image destination.
Service Details
Example of what you see in your service page.

What does a batch request look like?

Parameters

service_id : number
Required

Your service ID, which is a unique identifier for the service you are using. It's essential to include this in your request so that the server knows which service you are accessing.

callback : string

This is the callback URL. After the server processes your batch request and completes the specified transformations, it will send the response back to this URL.

source : string
Required

The source file that you want to transform. The source file must be in the storage that you have set up.

jobs : array
Required

This is an array of jobs to be applied to the source file - In this example we have a transformation.

Batch Example Request
		{
  "service_id": 1,
  "source": "/480x360/1.jpg",
  "jobs": [
    {
      "destination": "/480x360/transformed/1.jpg",
      "quality": 70,
      "transformations": [
        {
          "type": "annotation",
          "font": "Arial",
          "color": "#000000",
          "text": "Test text",
          "size": 10,
          "gravity": "center"
        }
      ]
    }
  ]
}
	

1.1 Jobs

Each job has its own destination, quality parameter and transformation array. Below are the parameters for each.

1.2.1 Batch Job Parameters

destination : string
Required

The destination of the transformed file. The destination file must be in the storage that you have set up.

quality : string

The quality of the transformed file. The quality can be a number between 0 and 100. Default is 70.

transformations : array
Required

This is an array of transformations to be applied to the source file.

Example Batch Job
		[
  {
    "destination": "/480x360/transformed/1.jpg",
    "quality": 70,
    "transformations": [
      {
        "type": "annotation",
        "font": "Arial",
        "color": "#000000",
        "text": "Test text",
        "size": 10,
        "gravity": "center"
      }
    ]
  }
]
	

1.2 Transformations

1.2.1 Annotation

type : 'annotation'
Required

font : string
Required

This parameter sets the font. Must be a string.

color : string
Required

This parameter sets the color. Must be hexadecimal.

text : string
Required

This parameter sets the text. Must be a string.

size : number
Required

This parameter sets the size. Must be a number.

gravity : string

This parameter sets the gravity. Must be one of 'center', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest'.

xoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

yoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

Example Annotation
		{
  "type": "annotation",
  "font": "Arial",
  "color": "#000000",
  "text": "Test text",
  "size": 10,
  "gravity": "center"
}
	

1.2.2 Blur

type : 'blur'
Required

sigma : number
Required

This parameter sets the sigma. Must be a number.

radius : number
Required

This parameter sets the radius. Must be a number.

Example Blur
		{
  "type": "blur",
  "sigma": 218,
  "radius": 465
}
	

1.2.3 Brightness

type : 'brightness'
Required

bright_level : number
Required

This parameter sets the brightness level. Must be a number between -255 and 255.

Example Brightness
		{
  "type": "brightness",
  "bright_level": 230
}
	

1.2.4 Colorize

type : 'colorize'
Required

red : number
Required

This parameter sets the red level. Must be a number between 0 and 255.

green : number
Required

This parameter sets the green level. Must be a number between 0 and 255.

blue : number
Required

This parameter sets the blue level. Must be a number between 0 and 255.

Example Colorize
		{
  "type": "colorize",
  "red": 200,
  "green": 120,
  "blue": 150
}
	

1.2.5 Contrast

type : 'contrast'
Required

level : number
Required

This parameter sets the contrast level. Must be a number between -100 and 100.

Example Contrast
		{
  "type": "contrast",
  "level": 55
}
	

1.2.6 Crop

type : 'crop'
Required

gravity : string
Required

This parameter sets the gravity. Must be one of 'center', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest'.

width : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original width: "100%"
Percentage of the original height: "100h"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

height : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original height: "100%"
Percentage of the original width: "100w"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

xoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

yoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

fit : boolean

This parameter calculates the best fit. Must be a boolean. Defaults to true.

Ensures that the image fits within certain dimensions (presumably maximum dimensions) while maintaining its original aspect ratio, if the fit parameter is set to true. It's a way to prevent the image from becoming too large or too distorted during resizing.

Example Crop
		{
  "type": "crop",
  "gravity": "center",
  "width": "750",
  "height": "500",
  "yoffset": "300",
  "xoffset": "500",
  "fit": true
}
	

1.2.7 Enhance

type : 'enhance'
Required

Example Enhance
		{
  "type": "enhance"
}
	

1.2.8 Filter

type : 'filter'
Required

filter : string
Required

This parameter sets the filter. Must be one of 'bw', 'sepia', 'negate', 'grayscale', 'edgedetect', 'emboss', 'blurgaussian', 'blurselective', 'meanremoval', 'smooth'.

Example Filter
		{
  "type": "filter",
  "filter": "sepia"
}
	

1.2.9 Fitmethod

type : 'fitmethod'
Required

color : string
Required

This parameter sets the color. Must be hexadecimal.

fit_type : string
Required

This parameter sets the fit type. Must be one of 'box', 'stretch', 'cropbox', 'letterbox', 'outside'.

gravity : string
Required

This parameter sets the gravity. Must be one of 'center', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest'.

width : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original width: "100%"
Percentage of the original height: "100h"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

height : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original height: "100%"
Percentage of the original width: "100w"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

opacity : number

This parameter sets the opacity. Must be a number between 0 and 10.

Example Fitmethod
		{
  "type": "fitmethod",
  "color": "#000000",
  "fit_type": "cropbox",
  "gravity": "center",
  "width": 550,
  "height": 300,
  "opacity": 0
}
	

1.2.10 Flip

type : 'flip'
Required

direction : string
Required

This parameter sets the direction of the flip. Must be one of 'x', 'y', 'vertical' or 'horizontal'.

Example Flip
		{
  "type": "flip",
  "direction": "y"
}
	

1.2.11 Resize

type : 'resize'
Required

width : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original width: "100%"
Percentage of the original height: "100h"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

height : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original height: "100%"
Percentage of the original width: "100w"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

Example Resize
		{
  "type": "resize",
  "width": 500,
  "height": 300
}
	

1.2.12 Rotate

type : 'rotate'
Required

degrees : number
Required

This parameter sets the degrees of the rotation. Must be a number between 0 and 360 with up to two decimal places.

Example Rotate
		{
  "type": "rotate",
  "degrees": 20
}
	

1.2.13 Ulb

type : 'ulb'
Required

Example Ulb
		{
  "type": "ulb"
}
	

1.2.14 Watermark

type : 'watermark'
Required

gravity : string
Required

This parameter sets the gravity. Must be one of 'center', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'northwest'.

width : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original width: "100%"
Percentage of the original height: "100h"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

height : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original height: "100%"
Percentage of the original width: "100w"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

Source : string
Required

This parameter sets the source of the watermark.

xoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

yoffset : string | number

Can be a negative value. Possible values:
Pixels: 100, "100" or "100px"
Percentage: "100%"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

Example Watermark
		{
  "type": "watermark",
  "gravity": "middle",
  "width": 200,
  "height": 200,
  "source": "watermark.png",
  "yoffset": 0,
  "xoffset": 0
}
	

1.2.15 Zoom

type : 'zoom'
Required

width : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original width: "100%"
Percentage of the original height: "100h"

Width Parameter with Percentage (%): Only one of 'width' or 'height' is required.

height : string | number
Required

Possible values:
Pixels: 100, "100" or "100px"
Percentage of the original height: "100%"
Percentage of the original width: "100w"

Height Parameter with Percentage (%): Only one of 'width' or 'height' is required.

level : number
Required

This parameter sets the level of zoom. Must be a number from 0 to 10.

Example Zoom
		{
  "type": "zoom",
  "width": "200",
  "height": "200",
  "level": 0
}
	

How to send a Batch request?

Head over to Postman:

  1. Method: Set the Method to POST.
  2. API URL: Set the URL to https://batch.slashed.cloud
  3. Go to Body and select raw and JSON.
  4. Copy and paste the JSON request above into the body.
    Note: Please make sure you insert YOUR service ID, source and destination.
  5. Batch Postman Request
  6. Go to Headers and add the following:
    Authorization: Bearer YourSecretKey
    Content-Type: application/json
  7. Batch Headers
  8. Click Send and you should get a response back with the status of your request.