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


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:

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 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, server for image optimization could not be reached.
  • 504 – Internal error, the image could not be retrieved from the servers.

Compatibility is 100% compatible with the old, non-functioning Yahoo webservice.

You just need to replace the old API call with the webservice URL, which works exactly like ?img=. has been verified to work perfectly with the Drupal module ImageAPI Optimize (dev version) and the official WordPress Image Optimizer plugin.

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


    $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, '');
    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);


Connection issues?

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

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