Image Stack image compression
Image Stack image compression allows you to reduce the weight of images in Image Stack formats .jpg
and .png
:
- reduce the quality;
- convert
.avif
or.webp
; - trim;
- to change size.
Principle of operation
Images on the source are stored in their original form. When the source receives a request to download an image of the format .jpg
and .png
The image goes to the Image Stack server, where it is processed according to the specified parameters. The processed image goes to the CDN-server cache.
In some cases, the image will not be processed and the user will receive the original version of the image:
- if the quality of the original image is lower than specified in the compression settings;
- the user's browser does not support the final format of the processed image;
- the source image has already been compressed using Gzip.
Cost
Image Stack is billed on a monthly basis on a data plan. The plan includes a package of 10,000 compression requests, which is used for all CDN resources of the account with Image Stack enabled. One image is processed per compression request.
The first payment under the tariff plan is deducted at the first activation of the option for any of the CDN resources of the account. The following payments are debited on the first day of each calendar month. If the package of requests under the tariff plan is exhausted, each request in excess of the package is charged separately according to the following model pay-as-you-go.
To view prices and calculate the cost of a CDN resource with the Image Stack option, please visit selectel.ru.
Customize Image Stack image compression
- Optional: turn on the source shilding.
- Enable compression in the control panel.
- If you want to crop and resize images and customize individual processing options for individual images, customize URL parameters on the website.
- Check the compression operation.
optional: enable source shilding
When you enable Image Stack, the cache of the CDN resource will be automatically cleared. All requests will start hitting the source, which may increase the load time of your site.
To avoid overloading the source, we recommend that you enable source shilding in advance. If source shilding is enabled, requests do not go directly to the source, but are accumulated on an intermediate shilding server. The shilding server caches content from the source and delivers it to CDN servers, thus relieving the load from the source. More details in the manual Source Schilding.
Enable compression in the control panel
In the control panel, you can customize the quality and format of the final images. You can customize cropping and resizing only using the URL parameters.
-
In control panels go to CDN → CDN resources.
-
Open the CDN resource page → tab Settings.
-
Check the box Image Stack.
-
To compress images, select quality — 95%, 80% or 65%, or select Its meaning and type it in.
-
In order not to change the quality of the format images
.png
and enable lossless compression for.png
. -
To convert the image format, enable compression
.avif
or.webp
.If you enable both compressions and the user's browser supports both formats, the image will load in the format
.avif
. If the user's browser does not support the final format, the original image will be loaded. -
Click Save.
customize URL parameters on the site
You can configure individual quality, format, cropping and resizing settings for each image via URL parameters. If you have set the quality and format in the control panel when compression enable and also set them through the URL-parameters of the image on the site, then the settings in the URL-parameters will be prioritized.
To spell out the URL parameters, add them to the image link:
https://<url>?<parameter>=<value>
Specify:
<url>
— path to the file;<parameter>=<value>
— the parameter to change and its value. To specify multiple parameters, list them using the symbol&
. You can see the possible parameters and their values in the table below URL parameters for Image Stack compression.
An example of a query that will translate the image image
formatted .png
in the format of .avif
will crop it to a size of 330 by 600 pixels relative to the center and reduce the quality to 50%:
https://cdn.example.com/images/image.png?fmt=avif&crop=300,600&quality=50
URL parameters for Image Stack compression
Check the compression work
-
Make sure that at least 30 minutes have passed since Image Stack was turned on — this time is necessary for the settings to apply to the CDN resource.
-
Open your browser in incognito mode.
-
Open Developer Tools → tab Network.
-
Open the page where you want the compressed images to be.
-
In the developer tools in the Name select the image that should have been downloaded from the CDN cache.
-
In the developer tools on the Headers en bloc Response headers look for the title
X-Img-Operations
:- if the header is in the list, the processed image has been loaded. The header value will indicate the processing performed (
compression
,convert
,resize
,crop
); - if the header is not in the list, the original image has been loaded. The reason why the image was not processed will be specified in the header Img-Skip-Reason.
- if the header is in the list, the processed image has been loaded. The header value will indicate the processing performed (