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)
reSmush.it 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 : http://api.resmush.it/ws.php?img=http://www.resmush.it/assets/images/jpg_example_original.jpg&qlty=95
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 :
Here is the list of the differents errors of the webservice :
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.
<?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
<?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);