API Reference and Developer Documentation
Preserving Metadata
By default Kraken.io API will strip all the metadata found in an image to make the image file as small as it is possible, and in both lossy and lossless modes. Entries like EXIF, XMP and IPTC tags, colour profile information, etc. will be stripped altogether.
However there are situations when you might want to preserve some of the meta information contained in the image, for example, copyright notice or geotags. In order to preserve the most important meta entries add an additional preserve_meta
array to your JSON request with one or more of the following values:
{
"preserve_meta": ["profile", "date", "copyright", "geotag", "orientation"]
}
profile | Will preserve the ICC colour profile. ICC colour profile information adds unnecessary bloat to images. However, preserving it can be necessary in extremely rare cases where removing this information could lead to a change in brightness and/or saturation of the resulting file. |
date | Will preserve image creation date. The following tags will be preserved (if present): Exif.Photo.DateTimeDigitized Exif.Photo.DateTimeOriginal Xmp.photoshop.DateCreated |
copyright | Will preserve copyright entries. The following tags will be preserved (if present): Exif.Image.Copyright Iptc.Application2.Copyright Xmp.dc.creator Xmp.dc.rights Xmp.photoshop.Credit |
geotag | Will preserve location-specific information. The following tags will be preserved (if present): Exif.GPSInfo.GPSLatitude Exif.GPSInfo.GPSLatitudeRef Exif.GPSInfo.GPSLongitude Exif.GPSInfo.GPSLongitudeRef Exif.GPSInfo.GPSVersionID |
orientation | Will preserve the orientation (rotation) mark. The following tag will be preserved (if present): Exif.Image.Orientation |
A complete request (that uses the URL option) with a preserve_meta
object that will preserve for example colour profile and geotag should look like the following:
{
"auth": {
"api_key": "your_api_key",
"api_secret": "your_api_secret"
},
"url": "https://example.com/image.png",
"wait": true,
"preserve_mets": ["profile", "geotag"]
}
<?php
require_once("Kraken.php");
$kraken = new Kraken("your_api_key", "your_api_secret");
$params = array(
"url" => "https://example.com/image.png",
"wait" => true,
"lossy" => true,
"preserve_meta" => array(
"profile",
"geotag"
)
);
$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: true,
preserve_meta: ["profile", "geotag"]
};
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,
:preserve_meta => ['profile', 'geotag']
}
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": true,
"preserve_meta": []interface {} {
"profile",
"geotag"
}
}
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 = true,
PreserveMeta = new PreserveMeta[] {
PreserveMeta.Profile,
PreserveMeta.Geotag
}
}
);
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,
'preserve_meta': ['profile', 'geotag']
}
result = api.url('https://example.com/image.png', data);
if result.get('success'):
print(result.get('kraked_url'))
else:
print(result.get('message'))