Free Image Compressor API

Basic call

To initiate a standard call and receive a JSON response, simply call this URL and specify the image like one of the following options:

  • GET – Parameter img
  • POST – Parameter img
  • FILES – Binary sent files

The webservice will return an array containing details about the compressed image, as described below.

API output

reSmush.it can return responses in:

  • JSON (XML is deprecated)

The output array contains various information, such as:

  • The source URL (when using the GET or POST method) (parameter src)
  • The URL of the optimized image (parameter dest)
  • The original file size (parameter src_size)
  • The optimized file size (parameter dest_size)
  • The percentage of improvement (parameter percent)
  • The date on which the file is to be deleted from the server (parameter expires)
  • The error code (parameter error)
  • The error description (parameter error_log)

Compression

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

  • qlty, with a value between 0 and 100. The default value is 92. To get a good image quality, the value should be above 90.

Example of use: https://api.resmush.it/ws.php?img=https://resmush.it/wp-content/uploads/2024/02/testimage.jpg&qlty=95

EXIF data

Since February 2017 (v.1.4.21), the EXIF data is removed by default to reduce the file size. However, this data can be retained during compression by specifying the following parameter in the GET method:

  • exif with the value true. The default value is false.

API Errors

Here is the list of the various errors of the web service:

  • 301 – Old endpoint used. Consider using api.resmush.it instead.
  • 400 – No image URL provided.
  • 401 – The image cannot be fetched from the URL (usually a local URL).
  • 402 – The image cannot be fetched from $_FILES (usually a local URL).
  • 403 – Forbidden file format specified. Only works with JPG, PNG, GIF, TIF and BMP files.
  • 404 – Unknown method or resource requested.
  • 501 – Internal error, cannot create a local copy.
  • 502 – Provided image too large (must be less than 5 MB).
  • 503 – Internal error, reSmush.it server for image optimization could not be reached.
  • 504 – Internal error, the image could not be retrieved from the reSmush.it servers.

Compatibility

reSmush.it is 100% compatible with the old, non-functioning Yahoo Smush.it webservice.

You just need to replace the old API call http://www.smushit.com/ysmush.it/ws.php?img= with the reSmush.it webservice URL, which works exactly like ?img=.

reSmush.it has been verified to work perfectly with the Drupal module ImageAPI Optimize (dev version) and the official WordPress reSmush.it Image Optimizer plugin.

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

Connection issues?

If you encounter any kind of connection issues or errors, please whitelist our IPs below and try again:

46.4.70.115
176.9.77.187
136.243.103.55
213.239.204.84
144.76.74.20
65.109.126.11
135.181.240.104

For a more advanced image optimization API including generate WebP and generate AVIF, consider exploring the ShortPixel API.