Operations - Image Optimization

Operations / Image Optimization

On this page:

Serving bloated, unoptimized images on your websites will have a very negative effect on your site speed and will lead to inevitable drops in conversions rates and customer satisfaction. Also, Google has indicated site speed is one of the important signals used by its algorithm to rank pages. Slower loading times will negatively affect your search ranking.

Image optimization is the art and science of minimizing image file size without affecting its visual quality. Our proprietary Smart Lossy Optimization algorithms excel at determining the perfect balance of image quality and file size, achieving on average 60% of savings without any perceptible impact on the image quality.

With Smart Lossy Optimization, you can also set a custom compression preset depending on your use-case. You may also bypass our smart image optimization pipeline and set a custom image quality level by yourself.

SupaRes API supports JPEG, PNG, Animated PNG, WebP, GIF, Animated GIF and SVG as input formats for image optimization pipeline.

Default Image Optimization Mode

It's worth noting that all images will be automatically optimized with Smart Lossy mode (unless you specify a lossless mode) and no additional user action is required to have your visuals prepared for the Web. In other words, SupaRes API will always yield perfectly optimized output images.

Smart Lossy Image Optimization

This is the default mode applied to all processed images. Images in JPEG, PNG, GIF, Animated GIF and SVG formats will be treated with Smart Lossy Optimization giving you confidence that your visuals will always have an unmatched quality with the smallest possible file size. Quality loss when using Smart Lossy Optimization is not noticeable to the human eye.

Because Smart Lossy Optimization is enabled by default, if you just want to optimize your images without performing any transformations, you only have to upload your file to the SupaRes API without any additional parameters.

An example cURL request incorporating Image Upload method used only to optimize your images would look like so:

curl https://api.supares.com/1.0/upload \
     --user your-api-key: \
     --form file=@/path/to/image/file.jpg

Or with Image Fetch method:

curl https://api.supares.com/1.0/fetch \
     --user your-api-key: \
     --header "Content-Type: application/json" \
     --data '{
         "url": "https://www.website.com/image.jpg"
     }'

Image Optimization Presets

In addition to the default smart lossy optimization mode which will yield images of excellent quality, the SupaRes API offers you five compression presets for different use-cases you may have. Those presets differ in terms of image quality and therefore the resulting file size; they describe the level of compression used to encode the output image.

Preset Description
lossless SupaRes API can apply mathematically lossless image optimization and recompression without altering a single pixel of the image. If you are confident that your image transformation requests must result in a pristine look of your visuals, you may use the lossless mode for image optimization.
low Low compression level is still lossy, but avoids any compression artifacts and therefore guarantees a bit higher file size savings than the lossless mode of image optimization. It's recommended for images with very high contrast ratio, gradients and visuals that will be enlarged on the client-side.
medium Medium compression level is enabled by default if the preset is not explicitly specified. If offers a perfect balance of file size and image quality and it's recommended for most use-cases. Quality degradation will be imperceptible under normal viewing conditions.
high High compression level guarantees the smallest possible file size at the expense of image quality. This mode is recommended for non-critical parts of your websites. It's also perfect for visuals prepared specificaly for high DPI screens (eg. Retina) as images on those screens will typically be scaled down by a factor of 2x and therefore compression artifacts will be less visible.
ultra Ultra compression bypasses all internal checks for image fidelity. Quality degradation will be noticable when comparing input and output visuals. This mode is reserved for use-cases where substantial byte savings (up to 95%) outweigh substantial loss in image quality. Use with caution.
{
    "optimize": {
        "compression": "high"
    }
}

An example cURL request of using Image Fetch method with lossy optimization preset will look like the following:

curl https://api.supares.com/1.0/fetch \
     --user your-api-key: \
     --header "Content-Type: application/json" \
     --data '{
         "url": "https://www.website.com/image.jpg",
         "optimize": {
             "compression": "high"
         }
     }'

Custom Image Quality

If you would like to exercise more control over the compression process, you may optionally specify an explicit quality (Q) value. To set the Q value, specify "quality": N within the optimize hash where N is an integer within the range 1 - 100 (1 being the lowest with maximum compression and 100 with the best image quality).

{
    "optimize": {
        "quality": 75
    }
}

We recommend against setting one quality value for all your visuals as for example Q75 might only look good on a small subset of images and specific image formats. It's always best to rely on our default Smart Lossy Optimization.

An example cURL request of using custom image quality will look like the following:

curl https://api.supares.com/1.0/fetch
     --user your-api-key: \
     --header "Content-Type: application/json" \
     --data '{
         "url": "https://www.website.com/image.jpg",
         "optimize": {
             "quality": 75
         }
     }'