Format and Encoding

Output Image Settings / Image Format and Encoding

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

The Pixaven Image API has a built-in image format conversion pattern. For example, if you supply a PSD file, the API will by default yield a JPEG on a white background. You may however override the default behaviour and request a different output image format. The default format mappings are presented below:

INPUT FORMATDEFAULT OUTPUT FORMAT
APNGAPNG
GIFGIF
HEICHEIC
JPEGJPEG
JPEG 2000JPEG 2000
PNGPNG
WebPWebP
TIFFJPEG
ICOPNG
PSDJPEG
BMPJPEG
SVGPNG

Animated GIF and Animated PNG images can be additionally converted to MP4 and WebM formats.

You only have to explicitly specify output format if you're not satisfied with our default mappings. For example, if you supply a JPEG image for processing and expect a progressive JPEG output file, you don't have to provide any additional settings in your request JSON.

APNG

APNG stands for Animated Portable Network Graphics and is an extension of the original PNG format. It supports both transparency and animation. APNG format is currently supported by Firefox, Chrome, Opera, Safari and iOS Safari browsers which translates to ~80% of global browser reach. The first frame of an APNG image is recognized as a normal PNG stream, so even browsers without full APNG decoding capabilities will display the first frame of an APNG file correctly.

To enforce APNG output, use apng as a format value within the output hash.

{
    "output": {
        "format": "apng"
    }
}

BMP

BMP is a Microsoft Windows standard format and was developed as a device-independent bitmap (DIB) format that will allow Windows to display the bitmap on any type of display device. It's a lossless format which does not support transparency nor animation and stores pixel data in uncompressed fashion.

Pixaven API fully supports BMP as input image format and, by default, will return a progressively encoded JPEG as a result of operations on BMP images.

GIF

GIF stands for Graphics Interchange Format and is a palette-based lossless raster image format which supports very limited transparency (one color) and animation (up to 10 frames per second). GIF can store up to 8 bits of color per pixel allowing for up to 256 colors per frame.

To enforce GIF output, use gif as a format value within the output hash.

{
    "output": {
        "format": "gif"
    }
}

HEIC

HEIC is a raster image compressed with HEVC codec and saved in the High Efficiency Image Format (HEIF). It's a lossy format which supports transparency. According to Apple, HEIC will take 50 percent less storage space than JPEG format of same photo without compromising the quality. HEIC is currently supported on iOS 11 devices (iPhone 7 and later) and MacOS High Sierra (10.13 and later).

To enforce HEIC output, use heic as a format value within the output hash.

{
    "output": {
        "format": "heic"
    }
}

ICO

ICO is an image file format for icons on Windows and was first introduced with Windows 1 in 1985. ICO files can contain one or more small images at multiple sizes and color depths, such that they may be scaled appropriately.

Please note that as per specification the ICO files must be in square dimensions with a fixed size of 16, 32, 48, 128, or 256 pixels.

Pixaven API fully supports ICO as input image format and, by default, will return a PNG image as a result of operations on ICO images.

JPEG

JPEG stands for Joint Photographic Experts Group and is the most popular raster image format on the Internet; it’s used mainly for large photograpic content. It's a lossy format which does not support transparency nor animation.

To enforce JPEG output, use jpg as a format value within the output hash.

All JPEG encoders and desktop image editing software (such as Photoshop) allow for setting JPEG output quality. This is a fundamental feature of a JPEG format and Pixaven also allows you to manually set the JPEG output quality. If you know what you're doing, you can specify quality which takes an integer in the range 1 - 100. Please note that usable range is usually around 70 - 90 mark. The value you specify with quality parameter will be passed directly to our JPEG encoders.

When converting to JPEG from vector formats such as SVG, you can also specify resolution which takes an integer in the range 72 - 300 and describes the number of pixels per inch. The default resolution value is 72.

{
    "output": {
        "format": "jpg",
        "quality": 75,
        "resolution": 150
    }
}

JPEG 2000

JPEG 2000 is considered to be the next iteration of JPEG image compression and can yield smaller file size with a better visual quality of the resulting image. JPEG 2000 is currently only supported by Safari and iOS Safari browsers which translates to ~13% of global browser reach. It's a lossy format which does not support transparency nor animation.

To enforce JPEG 2000 output, use jp2 as a format value within the output hash.

{
    "output": {
        "format": "jp2"
    }
}

PNG

PNG stands for Portable Network Graphics and is the second most popular raster image format on the Internet. It's a lossless format which supports transparency but does not support animation. Unlike GIF format, which only supports 8-bit color, PNG supports up to 24-bit color RGB with 8-bit transparency. This makes it an excellent format for images with alpha transparency and thousands of colors used. We highly recommend re-encoding your static GIF images into PNG format as the latter will always result in a smaller file size due to a more advanced compression algorithm.

To enforce PNG output, use png as a format value within the output hash.

{
    "output": {
        "format": "png"
    }
}

TIFF

TIFF stands for Tag Image File Format and is a common format for exchanging raster graphics between applications. A TIFF file can be used as a container holding lossy and losslessly compressed images and also can include a vector-based clipping path (outlines, croppings, image frames).

Pixaven API fully supports TIFF as input image format and, by default, will return a progressively encoded JPEG as a result of operations on TIFF images.

WebP

WebP is an emerging image format developed by Google and released in 2010. It employs both lossy as well as lossless compression techniques and supports both transparency and animation. According to Google, WebP lossless images are 26% smaller in size compared to PNGs and 25-34% smaller in size compared to JPEG images. WebP format is currently supported by Chrome, Edge, Opera, Opera Mini, Android Browser and Chrome for Android which translates to ~73% of global browser reach.

By default, the Pixaven API will produce lossy-compressed WebP images. If you'd like to use lossless compression, simply set "lossless": true within the output hash however we recommend to use the default lossy compression.

If you know what you're doing, you can also specify quality which takes an integer in the range 1 - 100. Please note that usable range is usually around 70 - 90 mark. The value you specify with quality parameter will be passed directly to WebP encoders.

To enforce WebP output, use webp as a format value within the output hash.

{
    "output": {
        "format": "webp",
        "lossless": true,
        "quality": 90
    }
}

WebM

WebM is a video file format hence this output only applies to Animated GIF images. Sponsored by Google, it exists as a royalty-free and open standard released under a standard BSD license. WebM format is currently supported by Edge, Firefox, Chrome, and Opera which translates to ~77% of global browser reach.

To enforce WebM output, use webm as a format value within the output hash.

{
    "output": {
        "format": "webm"
    }
}

MP4

MP4 is a commonly used video compression format which, just like WebM, only applies to Animated GIF images. It offers better compression quality over WebM which leads to slightly larger file sizes of output videos. MP4 format is currently supported by all major browsers and covers ~93% of global browser reach.

To enforce MP4 output, use mp4 as a format value within the output hash.

{
    "output": {
        "format": "mp4"
    }
}

Code Examples for Output Format

Below, you'll find examples of how to set the Output Format 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,
* resize the image to 100 x 75 and set output format to WebP
*/

$pix
    ->fetch('https://www.website.com/image.jpg')
    ->resize(array(
        'width' => 100,
        'height' => 75
    ))
    ->output(array(
        'format' => 'webp'
    ))
    ->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,
* resize the image to 100 x 75 and set output format to WebP
*/

pix
    .fetch("https://www.website.com/image.jpg")
    .resize({
        width: 100,
        height: 75
    })
    .output({
        format: "webp"
    })
    .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,
# resize the image to 100 x 75 and set output format to WebP

err, meta = pix
    .fetch("https://www.website.com/image.jpg")
    .resize(
        width: 100,
        height: 75
    )
    .output(
        format: "webp"
    )
    .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,
    * resize the image to 100 x 75 and set output format to WebP
    */

    meta, err := pix.
        Fetch("https://www.website.com/image.jpg").
        Resize(pixaven.P{
            "width": 100,
            "height": 75
        }).
        Output(pixaven.P{
            "format": "webp"
        }).
        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,
# resize the image to 100 x 75 and set output format to WebP

err, meta = (
    client
        .fetch('https://www.website.com/image.jpg')
        .resize({
            'width': 100,
            'height': 75
        })
        .output({
            'format': 'webp'
        })
        .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 FormatEncoding {
    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,
        * resize the image to 100 x 75 and set output format to WebP
        */

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

        fetch.resize(
            settings()
                .set("width", 100)
                .set("height", 75)
        );

        fetch.output(
            settings()
                .set("format", "webp")
        );

        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×