Output Image Settings - Format and Encoding

Output Image Settings / Format and Encoding

The Optidash API intelligently defaults to auto mode for determining the output image format, aligning the output format with that of the input. For instance, a JPEG input results in a JPEG output. Nevertheless, users have the flexibility to override this setting, specifying desired output formats from a wide array of supported options, including AVIF, GIF, JPEG, JPEG 2000, PNG, WebP, and additional formats for comprehensive imaging solutions.

AVIF (AV1 Image File Format)

Emerging from the AV1 video codec's keyframes, AVIF stands as a cutting-edge format offering superior compression efficiency over traditional formats like JPEG, PNG, and WebP. It's an excellent choice for web and application imagery where bandwidth efficiency is crucial.

To specify AVIF as the output format, include "format": "avif" within the output hash of your request.

{
    "output": {
        "format": "avif"
    }
}

GIF (Graphics Interchange Format)

GIF is a widely recognized format for its palette-based, lossless compression, limited transparency support (one color), and animation capabilities (up to 10 fps), accommodating up to 256 colors per frame.

To specify GIF as the output format, include "format": "gif" within the output hash of your request.

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

JPEG (Joint Photographic Experts Group)

As the internet's most prevalent raster format, JPEG is favored for photographic content, despite being a lossy format without support for transparency or animation.

For JPEG output, set "format": "jpg" in the output hash. Adjusting image quality is possible via the quality parameter, accepting values between 1 and 100, with a recommended range of 70 to 90.

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

JPEG 2000

Building upon JPEG, JPEG 2000 offers improved compression and visual quality. However, its support is limited mainly to Safari and iOS Safari, covering approximately 13% of global browser usage. Like its predecessor, it is a lossy format without transparency or animation support.

To specify JPEG 2000 as the output format, include "format": "jp2" within the output hash of your request.

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

PNG

Renowned for its lossless compression and support for transparency (but not animation), PNG stands out for its ability to handle up to 24-bit color RGB with 8-bit transparency, making it ideal for images requiring high color fidelity and transparency. 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 specify PNG as the output format, include "format": "png" within the output hash of your request.

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

WebP

Developed by Google, WebP combines lossy and lossless compression with support for transparency and animation. It generally offers smaller file sizes compared to PNGs and JPEGs.

By default, the API produces lossy WebP images. For lossless WebP, set "compression": "lossless" in the output hash. Nonetheless, default lossy compression is recommended for the best balance of file size and quality.

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.

For WebP output, set "format": "webp" in the output hash. Adjusting image quality is possible via the quality parameter, accepting values between 1 and 100, with a recommended range of 70 to 90.

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

Additional Formats

While the above details the primary formats, the Optidash API's versatility extends to accommodate other specific needs, ensuring broad compatibility and flexibility for developers looking to optimize their images for various platforms and devices.