: Image optimization API

API, How to use

Basic call

For a standard call, with a JSON response, you just have to call this url and provide the image attribute like one of these options below :

The webservice will return an array of informations about the compressed image (see below)

API output is able to answer in :

The output array contains several informations, such as :


Since July 2015 (v.1.4.2), you can now specify your optimization level for JPG compression. To do so, just add the following parameter in GET method :

For having a good image quality, please remain above 90

Example of use :

EXIF data

Since Feb 2017 (v.1.4.21), EXIF data are remove by default, reducing file size. However, these data can be keeped while compression by specifying the following parameter in GET method :

API Errors

Here is the list of the differents errors of the webservice :

Compatibility is 100% compatible with old non-working Yahoo webservice.

You'll just have to replace the old API call by the webservice url, which works exactly the same way and everything will be fine! has been tested successfully with Drupal's ImageAPI Optimize (dev version) module and with the official Wordpress plugin Image Optimizer.

Examples of implementation (PHP)

#1 Simple PHP request (using GET and with a JSON response)

define('WEBSERVICE', '');
$s = 'http://www.mywebsite/image.jpg';
$o = json_decode(file_get_contents(WEBSERVICE . $s));

echo $o->dest; //URL of the optimized picture

#2 Drupal implementation

Please use dev version of ImageAPI module, in order to include the image optimization. Thanks to Alan Tondelier.

$dst = drupal_realpath($dst);
$url = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('files' => '@' . $dst));
$data = curl_exec($ch);
$json = json_decode($data);

if (!isset($json->error)) {
	$result = drupal_http_request($json->dest);
	if (!isset($result->error)) {
	  file_unmanaged_save_data($result->data, $dst, FILE_EXISTS_REPLACE);
	  return TRUE;