API Reference and Developer Documentation

Lossy Image Optimization

Kraken.io's intelligent lossy image optimization applies a variety of techniques and processing steps to input images to recompress them to a lower quality level which falls below the human perceptible threshold.

In other words, we strive to preserve the visual identity and qualities of the image to the extent that you will not be able to, or at least find it very difficult, to tell the optimized ("Kraked") image from the original.

We use this mode ourselves, as do most of our customers. Typical file weight reductions range from 50%-60%, in many cases going all the way up to 90% mark. Kraken.io's lossy optimization will give you outstanding results with an imperceptible amount of quality loss. We want the Web to be faster while remaining beautiful.

We strongly recommend that you try out our lossy optimization.
It will drastically reduce the weight of your files, and you may not even notice any visible difference.

Most image optimizers simply slash image quality to a fixed level. At Kraken.io, we do not see this as an option; while a fixed quality setting can be good for one image, it will not be so for others, since compressibility is heavily content dependant, with some images ending up with unacceptable quality degradation - meaning results will need to be checked manually to ensure they are of publishable quality.

At Kraken.io we use an intelligent lossy optimization scheme, meaning Kraken.io will intelligently pick the best quality to size ratio for every single image. That way we can ensure results of outstanding image quality with the lowest possible file size.

To use our lossy optimization algorithms simply set the "lossy": true property in your request JSON:

{
    "auth": {
        "api_key": "your-api-key",
        "api_secret": "your-api-secret"
    },
    "url": "http://awesome-website.com/images/header.png",
    "wait": true,
    "lossy": true
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");

$params = array(
    "url" => "http://awesome-website.com/images/header.png",
    "wait" => true,
    "lossy" => 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: "http://awesome-website.com/images/header.png",
    wait: true,
    lossy: true
};

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,
    :lossy => true
}

data = kraken.url('http://awesome-website.com/images/header.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": "http://awesome-website.com/images/header.png"
        "wait": true,
        "lossy": true
    }

    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;

var client = Connection.Create("your-api-key", "your-api-secret");

var response = client.OptimizeWait(
    new OptimizeWaitRequest(
      new Uri("http://awesome-website.com/images/header.png"))
      {
          Lossy = true
      });

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,
    'lossy': True
}

result = api.url('http://awesome-website.com/images/header.png', data);

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

Custom Quality Settings

If you would like to override our intelligent quality settings for JPEG images pass an additional parameter quality which should be a number within the range of 1-100. For example:

{
  "auth": {
      "api_key": "your-api-key",
      "api_secret": "your-api-secret"
  },
  "url": "http://awesome-website.com/images/header.jpg",
  "wait": true,
  "lossy": true,
  "quality": 75
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");

$params = array(
    "url" => "http://awesome-website.com/images/header.jpg",
    "wait" => true,
    "lossy" => true,
    "quality" => 75
);

$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: "http://awesome-website.com/images/header.jpg",
    wait: true,
    lossy: true,
    quality: 75
};

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,
    :lossy => true,
    :quality => 75
}

data = kraken.url('http://awesome-website.com/images/header.jpg', 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": "http://awesome-website.com/images/header.jpg"
        "wait": true,
        "lossy": true,
        "quality": 75
    }

    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;

var client = Connection.Create("your-api-key", "your-api-secret");

var response = client.OptimizeWait(
    new OptimizeWaitRequest(
      new Uri("http://awesome-website.com/images/header.jpg"))
      {
          Lossy = true,
          Quality = 75
      });

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,
    'lossy': True,
    'quality': 75
}

result = api.url('http://awesome-website.com/images/header.png', data);

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

Read more on: