Filtering

Image Operations / Image Filtering

On this page:
Intro ▾
{{activeSubMenu.text}} ▾

The Pixaven Image API provides you with a powerful toolbelt of the highest quality filters you can apply on your images - from multiple modes of image blurring through sepia, duotone, monochrome or halftone to color replacement. You may of course stack as many different filters toghether as you like.

All filtering parameters must be passed within a filter hash and every filter, at minimum, accepts a value which takes a positive float within the range 0 - 100. For example, to apply a pixellate filter:

{
    "filter": {
        "pixellate": {
            "value": 10
        }
    }
}

An example cURL request with Image Fetch method of applying a pixellate filter will look like the following:

curl https://api.pixaven.com/1.0/fetch
     --user your-api-key: \
     --header "Content-Type: application/json" \
     --data '{
         "url": "https://www.website.com/image.jpg",
         "filter": {
             "pixellate": {
                 "value": 10
             }
         }
     }'

Using Multiple Filters

As previously mentioned, you can stack different filters together. To do so, simply add additional filters within the filter hash. For example, to apply a Sepia Tone filter together with Gaussian Blur:

{
    "filter": {
        "sepia": {
            "value": 10
        },
        "blur": {
            "mode": "gaussian",
            "value": 10
        }
    }
}

Duotone

This extremely artistic filter maps two input colors onto the darks and lights of an image. The resulting image is represented only with the shades of the two input colors.

The Duotone filter takes two parameters: light and dark which are color values to map onto the grayscaled input image. Both parameters take a color value as hex-encoded string in RGB or RRGGBB format.

{
    "filter": {
        "duotone": {
            "light": "6AFF7F",
            "dark": "00007E"
        }
    }
}
Filtered
Original

Gaussian Blur

This is one of the most widely used blurring algorithms. It blurs pixels by applying a convolution kernel which mixes in a fraction of the color of neighboring pixels. This will cause sharp color transitions to appear more gradual and results in a softness or blur of the image.

In order to use the Gaussian Blur filter, you must set the blur filter mode to gaussian and set a value which takes a float within the range 0 - 100, and describes the amount of blur applied to the input image.

{
    "filter": {
        "blur": {
            "mode": "gaussian",
            "value": 10
        }
    }
}
Filtered
Original

Motion Blur

Simulates the streak-like effect of a moving object usually achieved by setting a longer exposure time (slower shutter speed) while shooting a photo.

In order to use the Motion Blur filter, you must set the blur filter mode to motion and set a value which takes a float within the range 0 - 100, and describes the amount of blur applied to the input image.

You may optionally set the angle parameter which takes an integer within the range 0 - 360, and describes the direction in which the pixels will be spread across the image. The default angle is 90.

{
    "filter": {
        "blur": {
            "mode": "motion",
            "value": 10,
            "angle": 90
        }
    }
}
Filtered
Original

Zoom Blur

Simulates the effect of zooming a camera while shooting a photo.

In order to use the Zoom Blur filter, you must set the blur filter mode to zoom and set a value which takes a float within the range 0 - 100, and describes the amount of blur applied to the input image.

{
    "filter": {
        "blur": {
            "mode": "zoom",
            "value": 10
        }
    }
}
Filtered
Original

Sepia Tone

Modifies the color of each pixel within the image in a way that they fall into redish-brown tones.

In order to use the Sepia Tone filter, you must set a value within the sepia hash which takes a float within the range 0 - 100, and describes the amount of brown shading applied to the image.

{
    "filter": {
        "sepia": {
            "value": 10
        }
    }
}
Filtered
Original

Pixelate

Pixelates the image by mapping the image to colored squares whose color is defined by the average of the replaced pixels.

In order to use the Pixellate filter, you must set a value within the pixellate hash which takes a float within the range 0 - 100, and describes the size of image pixelation.

{
    "filter": {
        "pixellate": {
            "value": 10
        }
    }
}
Filtered
Original

Monochrome

Remaps the color of each pixel within the image so that it falls within the shades of a single color.

In order to use the Monochrome filter, you must set a value within the monochrome hash which takes a float within the range 0 - 100, and describes the intensity of the applied monochromatic hue and a color which takes a hex-encoded string in RGB, RRGGBB or AARRGGBB format. For example, to apply a semi-transparent blue 750015FF hue:

{
    "filter": {
        "monochrome": {
            "value": 10,
            "color": "750015FF"
        }
    }
}
Filtered
Original

Vignette

Reduces the brightness of an image at the periphery by applying a rounded darkening around the edges.

In order to use the Vignette filter, you must set a value within the vignette hash which takes a float within the range 0 - 100, and describes the intensity of applied darkening and a radius which takes a float within the range 0 - 100, and describes the size of applied darkening.

{
    "filter": {
        "vignette": {
            "value": 10,
            "radius": 10
        }
    }
}
Filtered
Original

Halftone

Applies a halftone effect by generating multiple dots with varying size and spacing.

In order to use the Halftone filter, you must set a value within the halftone hash which takes a float within the range 0 - 100, and describes the size and spacing of the generated dots.

{
    "filter": {
        "halftone": {
            "value": 10
        }
    }
}
Filtered
Original

Isolate Color

Isolates a given color by changing pixels whose color values fall outside of a specified color range into grayscale.

In order to use the Isolate Color filter, you must set a color within the isolate hash which takes a hex-encoded string in RGB, RRGGBB or AARRGGBB format and describes which color to isolate (preserve). You may also specify a threshold which takes a positive float within the range 0 - 1.0, and describes the amount of color isolation. The higher the threshold, the broader shades of the input color will be isolated.

{
    "filter": {
        "isolate": {
            "color": "DF7488",
            "threshold": 0.1
        }
    }
}
Filtered
Original

Code Examples for Image Stylizing

Below, you'll find examples of how to use the Image Stylizing from the Pixaven API:

<?php

/**
* Instantiate new `$pix` by calling a constructor
*/

$pix = new Pixaven\Pixaven('your-api-key');


/**
* Provide a publicly available image URL with fetch(string) method
* and apply Gaussian Blur and Sepia Tone filters
*/

$pix
    ->fetch('https://www.website.com/image.jpg')
    ->filter(array(
        'blur' => array(
            'mode' => 'gaussian',
            'value' => 10
        ),
        'sepia' => array(
            'value' => 20
        )
    ))
    ->toJSON(function ($error, $meta) {
        if (!empty($error)) {
            throw new Exception($error);
        }

        /**
        * You'll find the full JSON metadata array within the `$meta` variable.
        * Remember to always check if the `success` property is set to `true`.
        */

        if ($meta['success'] == true) {
            print ($meta['output']['url']);
        } else {
            print ($meta['message']);
        }
    });
/**
* Module dependencies
*/

const Pixaven = require("pixaven");


/**
* Instantiate new `pix` by calling a constructor
*/

const pix = new Pixaven("your-api-key");


/**
* Provide a publicly available image URL with fetch(string) method
* and apply Gaussian Blur and Sepia Tone filters
*/

pix
    .fetch("https://www.website.com/image.jpg")
    .filter({
        blur: {
            mode: "gaussian",
            value: 10
        },
        sepia: {
            value: 20
        }
    })
    .toJSON((err, meta) => {
        if (err) {
            return console.log(err);
        }

        /**
        * You'll find the full JSON metadata hash within the `meta` variable.
        * Remember to always check if the `success` property is set to `true`.
        */

        if (meta.success) {
            console.log(meta.output.url);
        } else {
            console.log(meta.message);
        }
    });
##
# Require dependencies

require "pixaven"


##
# Instantiate new `pix` by calling a constructor

pix = Pixaven.new("your-api-key")


##
# Provide a publicly available image URL with fetch(string) method
# and apply Gaussian Blur and Sepia Tone filters

err, meta = pix
    .fetch("https://www.website.com/image.jpg")
    .filter(
        blur: {
            mode: "gaussian",
            value: 10
        },
        sepia: {
            value: 20
        }
    )
    .to_json

abort(err) if err


##
# You'll find the full JSON metadata hash within the `meta` variable.
# Remember to always check if the `success` property is set to `true`.

if meta["success"]
    puts meta["output"]["url"]
else
    puts meta["message"]
end
package main

import (
    "fmt"
    "github.com/pixaven/pixaven-go"
)

func main() {

    /**
    * Instantiate new `pix` by calling a constructor
    */

    pix, err := pixaven.NewClient("your-api-key")

    if err != nil {
        panic(err)
    }


    /**
    * Provide a publicly available image URL with Fetch(string) method
    * and apply Gaussian Blur and Sepia Tone filters
    */

    meta, err := pix.
        Fetch("https://www.website.com/image.jpg").
        Filter(pixaven.P{
            "blur": pixaven.P{
                "mode": "gaussian",
                "value": 10
            },
            "sepia": pixaven.P{
                "value": 20
            }
        }).
        ToJSON()

    if err != nil {
        panic(err)
    }


    /**
    * You'll find the full JSON metadata hash within the `meta` variable.
    * Remember to always check if the `success` property is set to `true`.
    */

    if meta["success"].(map[string]interface{})["success"].(bool) {
        fmt.Println(meta["output"].(map[string]interface{})["url"])
    } else {
        fmt.Println(meta["message"])
    }
}
##
# Import dependencies

from pixaven import pixaven


##
# Instantiate new `client` by calling a constructor

client = pixaven('your-api-key')


##
# Provide a publicly available image URL with fetch(string) method
# and apply Gaussian Blur and Sepia Tone filters

err, meta = (
    client
        .fetch('https://www.website.com/image.jpg')
        .filter({
            'blur': {
                'mode': 'gaussian',
                'value': 10
            },
            'sepia': {
                'value': 20
            }
        })
        .toJSON()
)

if err is not None:
    raise StandardError(err)


##
# You'll find the full JSON metadata hash within the `meta` variable.
# Remember to always check if the `success` property is set to `true`.

if meta['success'] is True:
    print (meta['output']['url'])
else:
    print (meta['message'])
package com.pixaven.examples;

/**
* Import dependencies
*/

import static com.pixaven.OperationConfiguration.settings;
import com.pixaven.Pixaven;
import com.pixaven.Fetch;
import com.pixaven.Response;

public class Stylizing {
    public static void main(String[] args) {

        /**
        * Instantiate new `pix` by calling a constructor
        */

        Pixaven pix = new Pixaven("your-api-key");

        /**
        * Provide a publicly available image URL with fetch(string) method
        * and apply Gaussian Blur and Sepia Tone filters
        */

        final Fetch fetch = pix.fetch("https://www.website.com/image.jpg");

        fetch.filter(
            settings()
                .set("blur", settings()
                    .set("mode", "gaussian")
                    .set("value", 10)
                )
                .set("sepia", settings()
                    .set("value", 20)
            )
        );

        final Response response = fetch.toJson();

        /**
        * You'll find the full JSON metadata hash within the `Response#getMetadata()` property.
        * Remember to always check if the `Response#successful` property is set to `true`.
        */

        if (response.isSuccessful()) {
            System.out.println(response.getMetadata().getOutput().get("url"));
        } else {
            System.out.println(response.getMessage());
        }
    }
}

We use both proprietary and third-party cookies to improve your browsing experience and to provide you with a better service. By continuing to use this site you consent our use of cookies as described in our Cookie Policy×