reSmush.it : Image optimization API

API, How to use

Basic call

For a standard call, with a JSON response, you just have to call this url http://api.resmush.it/ws.php 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

reSmush.it is able to answer in :

The output array contains several informations, such as :

Compression

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 : http://api.resmush.it/ws.php?img=http://www.resmush.it/assets/images/jpg_example_original.jpg&qlty=95

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

reSmush.it is 100% compatible with old non-working Yahoo Smush.it webservice.

You'll just have to replace the old API call http://www.smushit.com/ysmush.it/ws.php?img= by the reSmush.it webservice url, which works exactly the same way http://api.resmush.it/ws.php?img= and everything will be fine!

reSmush.it has been tested successfully with Drupal's ImageAPI Optimize (dev version) module and with the reSmush.it official Wordpress plugin reSmush.it Image Optimizer.

Examples of implementation (PHP)

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

<?php
define('WEBSERVICE', 'http://api.resmush.it/ws.php?img=');
$s = 'http://www.mywebsite/image.jpg';
$o = json_decode(file_get_contents(WEBSERVICE . $s));

if(isset($o->error)){
	die('Error');
}
echo $o->dest; //URL of the optimized picture
	

#2 Drupal implementation

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

<?php
$dst = drupal_realpath($dst);
$url = 'http://api.resmush.it/ws.php';
$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);
curl_close($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;
	}
}