API Reference and Developer Documentation

Lossless Image Optimization

Kraken.io API's default image compression mode is lossless. Lossless optimization means that your images will get compressed to some extent without changing their informational value in any way whatsoever.

Reductions in terms of file weight are usually in the 15%-20% range, however sometimes greater savings can be achieved, especially where images have uniformly coloured backgrounds and/or pack lots of metadata.

We have found that most of our customers use Kraken.io API's lossy optimization mode, which yields much greater file size reductions while having no perceptible impact on the quality of the resulting image. We use that mode ourselves and suggest that you give it a try.

Kraken.io's lossless image compression is achieved by applying a variety of techniques and processing steps to the image to reduce its file weight or byte size without changing a single pixel. Therefore, the original image will always be perfectly reconstructable from the compressed one.

There are two ways to tell Kraken.io to losslessly compress your images. You can either explicitly set the "lossy": false flag in your request JSON, or omit it entirely.

To illustrate, the examples below are a mix of cases of both explicity setting the lossy property and leaving it out altogether:

{
    "auth": {
        "api_key": "your_api_key",
        "api_secret": "your_api_secret"
    },
    "url": "https://example.com/image.png",
    "wait": true,
    "lossy": false
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your_api_key", "your_api_secret");

// here we omit the "lossy": false flag altogether, so the API defaults to lossless mode
$params = array(
    "url" => "https://example.com/image.png",
    "wait" => true
);

$data = $kraken->url($params);

if ($data["success"]) {
    echo "Success. Optimized image URL: " . $data["kraked_url"];
} else {
    echo "Fail. Error message: " . $data["message"];
}
var Kraken = require("kraken");

var kraken = new Kraken({
    "api_key": "your_api_key",
    "api_secret": "your_api_secret"
});

var params = {
    url: "https://example.com/image.png",
    wait: true,
    lossy: false
};

kraken.url(params, function(status) {
    if (status.success) {
        console.log("Success. Optimized image URL: %s", status.kraked_url);
    } else {
        console.log("Fail. Error message: %s", status.message);
    }
});
require 'rubygems'
require 'kraken-io'

kraken = Kraken::API.new(
    :api_key => 'your_api_key',
    :api_secret => 'your_api_secret'
)

params = {
    :wait => true
}

data = kraken.url('https://example.com/image.png', params)

if data.success
    puts 'Success! Optimized image URL: ' + data.kraked_url
else
    puts 'Fail. Error message: ' + data.message
end
package main

import (
    "log"
    "github.com/kraken-io/kraken-go"
)

func main() {
    kr, err := kraken.New("your_api_key", "your_api_secret")

    if err != nil {
        log.Fatal(err)
    }

    params := map[string]interface {} {
        "url": "https://example.com/image.png"
        "wait": true,
        "lossy": false
    }

    data, err := kr.URL(params)

    if err != nil {
        log.Fatal(err)
    }

    if data["success"] != true {
        log.Println("Failed, error message ", data["message"])
    } else {
        log.Println("Success, Optimized image URL: ", data["kraked_url"])
    }
}
using Kraken;
using Kraken.Http;
using Kraken.Model;

var connection = Connection.Create("your_api_key", "your_api_secret");
var client = new Client(connection);
var response = client.OptimizeWait(
    new OptimizeWaitRequest(new Uri("https://example.com/image.png"))
    {
        Lossy = false
    }
);

if (response.Result.StatusCode == HttpStatusCode.OK) {
    var url = response.Result.Body.KrakedUrl;
}
from krakenio import Client

api = Client('your_api_key', 'your_api_secret')

data = {
    'wait': True
}

result = api.url('https://example.com/image.png', data);

if result.get('success'):
    print(result.get('kraked_url'))
else:
    print(result.get('message'))

Read more on: