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. |
|
Posible values
|
|
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. |
|
If this field is not defined, then the default parameters will be used. If defined, it needs to be an array with the same number of lines as the URLs sent to be optimized.
Each line contains the custom optimization parameters for each of the URLs. |
|
This field can be left empty or it can contain any type of array. If an array is defined, then it will be returned unchanged, in the API response. |
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. |
WebPLossyURL |
If the convertto=+webp or convertto=webp option was provided, it contains the download URL for the image optimized and converted to WebP using lossy/glossy compression. Otherwise will return "NA". "+" means that the original image will be also optimized. |
WebPLosslessURL |
If the convertto=+webp or convertto=webp option was provided, it contains the download URL for the image optimized and converted to WebP using lossless compression. Otherwise will return "NA". "+" means that the original image will be also optimized. |
AVIFLossyURL |
If the convertto=+avif or convertto=avif option was provided, it contains the download URL for the image optimized and converted to AVIF using lossy/glossy compression. Otherwise will return "NA". "+" means that the original image will be also optimized. |
AVIFLosslessURL |
If the convertto=+avif or convertto=avif option was provided, it contains the download URL for the image optimized and converted to AVIF using lossless compression. Otherwise will return "NA". "+" means that the original image will be also optimized. |
OriginalSize |
Size of the original image. |
LossySize |
Size of the lossy/glossy compressed image. |
LoselessSize |
Size of the lossless compressed image. |
WebPLossySize |
Size of the lossy/glossy WebP compressed image. |
WebPLoselessSize |
Size of the lossless WebP compressed image. |
AVIFPLossySize |
Size of the lossy/glossy AVIF compressed image. |
AVIFLoselessSize |
Size of the lossless AVIF 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.
Use the ShortPixelNet\ShortPixel class and follow the examples from this .NET example project: ShortPixel.NET. The ShortPixel C# class supports both the Reducer and the PostReducer API points. The initial version of this project was kindly provided by Michael Dyhr Iversen.
An older C# 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 and the posted files, or file_urls.
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:
|
|
Use the ShortPixelNet\ShortPixel class and follow the examples from this .NET example project: ShortPixel.NET. The ShortPixel C# class supports both the Reducer and the PostReducer API points. The initial version of this project was kindly provided by Michael Dyhr Iversen.
Code example courtesy of Marco Flores |
|
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:
|