Functions

Functions are the operations that can be performed on images.

A job can have 1 or more functions, and you can pipeline functions so that the output of 1 function is the input to the next function.

A complete list of functions can be found here

HOW DO FUNCTIONS WORK?

Functions have a name node and the have a params node. Much like functions in a programming language, the params are fed into the function. Many params are optional and have default values.

A typical function looks like this:

{
    "name":"annotate",
    "params":{
        "text":"my_text",
        "color":"#ffffff"
    }
}

Once a function has been completed on an image, you can set a location to save the image. Typically, this is your S3 or Azure location (but blitline will default to it’s own temporary bucket if no destination is given).

When you save an image, you must give it an image_identifier which is how this output image will be referred to in later JSON interaction. An image_identifier is just a name you give to an image, Blitline only cares that it exists and doesn’t care about it’s content.

To output an image after a function has completed just add a save node to the function node. For example:

{
    "name":"annotate",
    "params":{
        "text":"my_text",
        "color":"#ffffff"
    },
    "save" : {
        "image_identifier" : "my_annotated_image",
        "s3_destination" : {
            "key" : "my_key/to_my_image/image.png",
            "bucket" : "my_s3_bucket"
        }
    }
}

In this example we have a save field which has an image-identifier as well as an s3_destination defined. The s3_destination simply contains an s3 key and bucket. You will need to setup S3 permissions to allow Blitline to write to your bucket.

CHAINING FUNCTIONS

A common scenario is that you may want to chain functions together, such as annotating an image, and then resizing it to a smaller thumbnail. You can easily accomplish this by adding functions inside of other functions. For example:

{
    "name": "annotate",
    "params": {
        "text": "my_text",
        "color": "#ffffff"
    },
    "save": {
        "image_identifier": "my_annotated_image",
        "s3_destination": {
            "key": "my_key/to_my_image/image.png",
            "bucket": "my_s3_bucket"
        }
    },
    "functions": [
        {
            "name": "resize_to_fit",
            "params": {
                "width": 300
            },
            "save": {
                "image_identifier": "my_annotated_resized_thumbnail",
                "s3_destination": {
                    "key": "my_key/to_my_image/image.png",
                    "bucket": "my_s3_bucket"
                }
            }
        }
    ]
}

In the example above, we see a new functions array inside the parent functions array node. This indicates that the parent function will be performed and the embedded function will be performed on the output of the parent functions