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 PHP Request (sending file directly to the API). Recommended method !

<?php

    $file = '/path/to/myfile.jpg';
    $mime = mime_content_type($file);
    $info = pathinfo($file);
    $name = $info['basename'];
    $output = new CURLFile($file, $mime, $name);
    $data = array(
        "files" => $output,
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://api.resmush.it/?qlty=80');
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
       $result = curl_error($ch);
    }
    curl_close ($ch);

    var_dump($result);