> ## Documentation Index
> Fetch the complete documentation index at: https://gcore-doc-1894.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure image compression to WebP and AVIF

Compression converts JPG and PNG images to WebP or AVIF format during CDN delivery, reducing file size without visible quality loss. WebP and AVIF use advanced compression algorithms — the painting by Wassily Kandinsky below demonstrates: sharpness and color rendering are the same across formats, but the WebP and AVIF files are smaller.

To apply compression, configure it in the [Gcore Customer Portal](https://portal.gcore.com) or add the `fmt` query string to individual image URLs.

<Tabs>
  <Tab title="PNG (1860 KB)">
    <Frame>
      <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965206801.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=f08c0be255b77e63b60016b8f529509f" alt="PNG example" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965206801.png" />
    </Frame>
  </Tab>

  <Tab title="JPG (169 KB)">
    <Frame>
      <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965205905.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=f49aa4e7aa526c0684e387b4ee5bc256" alt="JPG example" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965205905.png" />
    </Frame>
  </Tab>

  <Tab title="WebP (136 KB)">
    <Frame>
      <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965337873.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=e380b2fc977f0b0dda06d30f8ce128ea" alt="WebP example" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965337873.png" />
    </Frame>
  </Tab>

  <Tab title="AVIF (113 KB)">
    <Frame>
      <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965357457.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=e5f9358a0c5cac6f6fdd242e3ee72b7d" alt="AVIF example" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965357457.png" />
    </Frame>
  </Tab>
</Tabs>

## Enable compression

Compression is part of the paid Image Stack option, which also supports resizing, cropping, and quality adjustment. Before enabling compression, activate Image Stack — [Enable Image Stack](/cdn/cdn-resource-options/image-optimization-paid/enable-image-stack).

## Use compression

Two methods are available: the Gcore Customer Portal and query strings. The portal method applies compression to all images matching the rule's URL pattern. The query string method applies compression per individual image URL.

### Use compression in the customer portal

1\. Navigate to **Rules** in the CDN resource and open the **Image optimization** rule.

<Frame>
  <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/configure-image-compression-image1.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=06df353b2ba7185d1065053f2c8f46ed" alt="Rules list showing the Image optimization rule" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/configure-image-compression-image1.png" />
</Frame>

2\. Select **Enable WebP compression** and/or **Enable AVIF compression**. When both are enabled, the format is chosen based on browser support — browsers that support both receive AVIF.

<Frame>
  <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/configure-image-compression-image2.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=f31e5f6d8efb35103c3234945c7e527c" alt="Image Stack settings with Enable WebP compression and Enable AVIF compression checkboxes" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/configure-image-compression-image2.png" />
</Frame>

3\. Click **Save changes** at the top right of the page.

Images are served in WebP or AVIF format to supported browsers.

### Use compression via query parameters

1\. Open the website source code.

2\. Find the URLs of the images to convert.

3\. Add a query string to each image URL:

```
image.jpg?fmt=value
```

where `value` is one of:

* `webp` — converts to WebP format
* `avif` — converts to AVIF format
* `avif,webp` — converts to WebP or AVIF based on browser support: `image.jpg?fmt=avif,webp`

4\. Save the changes. Images are served in the configured format.

## Check HTTP headers

After converting, an image does not change its URL or extension. Use the HTTP response headers to verify the conversion.

The `X-Img-Operations` header reflects all the conversions performed. If the value includes `convert`, the image format has been converted.

The `Content-Type` header shows the compression format. The value `image/webp` or `image/avif` confirms the image is in the new format.

<Frame>
  <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965537425.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=9e8fdcd64dc51203f951a081c0714ad4" alt="X-Img-Operations and Content-Type headers in a CDN response showing successful WebP conversion" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028965537425.png" />
</Frame>

If the `X-Img-Operations` header contains no convert value and the CDN returns the image with original quality, inspect the `Img-Skip-Reason` HTTP header for the skip reason. The value `converted image bigger than origin value` means the configured quality exceeds the source image quality — lower the quality setting in [Change image quality](/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/change-image-quality).

<Frame>
  <img src="https://mintcdn.com/gcore-doc-1894/D4afn3gx_zp92kAa/images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028973043857.png?fit=max&auto=format&n=D4afn3gx_zp92kAa&q=85&s=d5de0c0a05899abb137781cfc8a3c913" alt="Img-Skip-Reason header showing why the image conversion was skipped" width="70%" data-path="images/docs/cdn/cdn-resource-options/image-optimization-paid/image-stack-tools/configure-image-compression-to-webp-and-avif/11028973043857.png" />
</Frame>
