Our services can be accessed through the powerful and easy-to-use Reducer API that covers all optimizing needs with just one method call.
If you are using WordPress, just install our WordPress plugin and you'll be up and running in seconds, without any implementation effort.
We also offer a PHP client library that features quick configuration and an easy fluent syntax for accessing our services, thus greatly reducing your implementation time.
The Reducer API allows you to shrink an image based on the URL of the image. The image has to be available online in order to be shrunk via this API. You can call it from any programming language that allows you to send an HTTP POST request.
Calling method | Parameters |
---|---|
POST |
URL to call: https://api.shortpixel.com/v2/reducer.php {"key": "your api key", "plugin_version": "MY123", "lossy": 1, "resize": 1, "resize_width": 1024, "resize_height": 1024, "cmyk2rgb": 1, "keep_exif": 0, "convertto": "+webp", "refresh": 0, "urllist": ["url1", "url2"]} JSON Encoded parameters, as follows
|
Parameter | Description |
---|---|
{key} |
Your API key, as provided in your ShortPixel control panel and signup confirmation email. |
{plugin_version} |
5 chars max., alphanumeric. Choose a code for your API client (MY123, RR007 for a Ruby on Rails client, etc.). |
{lossy} |
Controls whether the image compression will use a lossy or lossless algorithm.
|
|
Set it between |
|
The type of resizing applied to the image.
|
|
The width in pixels for the resize. Needed only if resize > 1. |
|
The height in pixels for the resize. Needed only if resize > 1. |
|
Convert CMYK to RGB, default is set to 1. Images for the web only need RGB format and converting them from CMYK to RGB makes them smaller. |
|
Keep the EXIF tag of the image. Default is set to 0, meaning the EXIF tag is removed. |
|
Convert also to other image types, when optimizing. For converting to WebP use "+webp". It is also possible to convert images from jpeg, png, gif, bmp and tiff to jpeg, png or gif. Just use "jpg", "png" or "gif" to select to what format you want to convert. Leave it empty if no conversion is needed. |
|
If refresh is set to 1, the image is fetched again by our servers from the source and re-optimized. Otherwise, if the image is already optimized and still available on our servers, the currently optimized image info is returned. |
|
The list of URLs where the original image is located. They need to be valid, maximum 100 URLs are allowed. |
The API call returns a JSON encoded data structure that shows the outcome of the call.
Field | Meaning |
---|---|
Status |
Contains the status message for the call. The status itself is an object with two fields:
|
OriginalURL |
This is the original URL provided in the API call. |
LossyURL |
Download URL for the optimized image using lossy/glossy compression. |
LosslessURL |
Download URL for the optimized image using lossless compression. |
OriginalSize |
Size of the original image. |
LossySize |
Size of the lossy/glossy compressed image. |
LoselessSize |
Size of the lossless compressed image. |
Timestamp |
Timestamp of the file processing. |
The syncronized api point uses the following URL: https://api.shortpixel.com/v2/reducer-sync.php and the parameters are the same except for {url}
containing the URL string, instead of the {urllist}
array. This API point returns the optimized image directly with image/...
mimetype header.
|
JavaScript example using JQuery:
|
Check out this demo HTML/JavaScript page for a working example.
|
|
The POST Reducer API allows you to shrink an image that is not accessible online, by uploading it to our servers via a POST HTTP call. You can call it from any programming language that allows you to send an HTTP POST request.
Because you are sending the files along with the POST request, you need to create a multipart POST request (instead of a JSON request as in Reducer API's case) that contains the parameters and the files. The server answer has the same structure as the one from Reducer API, though.
Calling method | Parameters |
---|---|
POST |
URL to call: https://api.shortpixel.com/v2/post-reducer.php The parameters are the same as for the Reducer API except the urllist that is replaced by either file_paths or file_urls and the posted files.
The parameters are sent as a multipart POST request, as in the following example (for PHP, see below a code snippet that generates a multipart POST request):
|
Parameter | Description |
---|---|
{file_paths} |
The local file full paths as a json-encoded key-value array where the key is the same as the name of the file sent (file1 ...). You can provide any string for the value, but it should be unique to the file sent. |
{file_urls} |
The corresponding OriginalURLs sent by the API as answer to a previous call for the same filename. Please provide only either file_paths or file_urls. |
The API call returns a JSON encoded data structure that shows the outcome of the call, similarily with the Reducer API return above. There are some additional fields and error codes, though:
Field | Meaning |
---|---|
Status |
Contains the status message for the call. The status itself is an object with two fields:
|
|
Code example courtesy of Marco Flores |
Code example courtesy of Rodrigo Nicola |
If the call to post-reducer returns Status=1, Message='Image scheduled for processing'
, you will need to call after a few seconds the reducer end-point, like this:
|