API Reference and Developer Documentation

Integration Examples — Image URL

Examples below show how you can pass your image URL for optimization and compression in various programming languages and parse the response body.

/**
* NOTE: First download our official PHP library from:
* https://github.com/kraken-io/kraken-php
*
* Or install via composer:
* composer require kraken-io/kraken-php
*/

require_once("Kraken.php");

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

$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"];
}


// For advanced API usage simply alter the `$params` array. For example:

$params = array(
    "url" => "https://awesome-website.com/images/header.jpg",
    "wait" => true,
    "resize" => array(
        "width" => 100,
        "height" => 75,
        "strategy" => "crop"
    ),
    "s3_store" => array(
        "key" => "your_amazon_access_key",
        "secret" => "your_amazon_secret_key",
        "bucket" => "assets",
        "path" => "images/layout/header.jpg"
    ),
    "webp" => true,
    "lossy" => true
);
// NOTE: First install our official Node module:
// $ npm install kraken --save

var Kraken = require('kraken');

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

var params = {
    url: 'https://awesome-website.com/images/header.jpg',
    wait: true
};

kraken.url(params, function(err, data) {
    if (err) {
        console.log('Failed. Error message: %s', err);
    } else {
        console.log('Success. Optimized image URL: %s', data.kraked_url);
    }
});


// For advanced API usage simply alter the `params` object. For example:

var params = {
    url: 'https://example.com/image.png',
    wait: true,
    resize: {
        width: 100,
        height: 75,
        strategy: 'crop'
    },
    s3_store: {
        key: 'your_amazon_access_key',
        secret: 'your_amazon_secret_key',
        bucket: 'assets',
        path: 'images/layout/header.jpg'
    },
    webp: true,
    lossy: true
};
# NOTE: First install our official Ruby gem:
# $ gem install kraken-io

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://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


# For advanced API usage simply alter the `params` hash. For example:

params = {
    :wait => true,
    'resize' => {
        'width' => 100,
        'height' => 75,
        'strategy' => 'crop'
    },
    's3_store' => {
        'key' => 'your_amazon_access_key',
        'secret' => 'your_amazon_secret_key',
        'bucket' => 'assets',
        'path' => 'images/layout/header.jpg'
    },
    'webp' => true,
    'lossy' => true
}
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 {} {
        "wait": true,
        "url": "https://awesome-website.com/images/header.jpg"
    }

    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"])
    }
}


// For advanced API usage simply alter the `params` hash. For example:

params := map[string]interface {} {
    "wait": true,
    "url": "https://awesome-website.com/images/header.jpg"
    "lossy": true,
    "webp": true,
    "resize": map[string]interface {} {
        "width": 100,
        "height": 75,
        "strategy": "crop"
    },
    "s3_store": map[string]interface {} {
        "key": "your_amazon_access_key",
        "secret": "your_amazon_secret_key",
        "bucket": "destination_bucket",
        "path": "images/layout/header.jpg"
    }
}
/// To install kraken-net, run the following command in the Package Manager Console:
/// Install-Package kraken-net

using Kraken;
using Kraken.Http;

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

if (response.Result.StatusCode == HttpStatusCode.OK) {
    var url = response.Result.Body.KrakedUrl;
}
# NOTE: First install our official Python Client:
# pip install krakenio

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'))


# For advanced API usage simply alter the `data` object. For example:

data = {
    'wait': True,
    'resize': {
        'width': 100,
        'height': 75,
        'strategy': 'crop'
    },
    's3_store': {
        'key': 'your_amazon_access_key',
        'secret': 'your_amazon_secret_key',
        'bucket": "destination_bucket",
        'path': 'images/layout/header.jpg'
    },
    'webp': True,
    'lossy': True
}