image_filter_webp_quality
Sets the quality of WebP images during filtering in NGINX.
Description
The image_filter_webp_quality directive is used to define the quality level of WebP images that are created when the image_filter module is utilized in NGINX. This directive accepts a single argument, which is an integer value specifying the quality (from 0 to 100) of the output WebP image, where 100 represents the highest quality and lowest compression, while 0 yields the lowest quality and maximum compression. The directive must be included in the configuration files within the http, server, or location contexts, as it is designed to control how images are processed and served.
When configured, image_filter_webp_quality enhances the image serving capabilities of NGINX by converting incoming images to the WebP format, which is often smaller in size compared to other formats like JPEG or PNG without significantly sacrificing visual quality. This conversion occurs on-the-fly if the client supports the WebP format, determined by inspecting the Accept header in the HTTP request. Properly setting the quality parameter allows developers to balance between image clarity and file size efficiency based on the specific needs of their application, thereby improving load times and performance for image-heavy web pages.
Config Example
location /images {
image_filter png;
image_filter_webp on;
image_filter_webp_quality 85;
}Ensure that the image_filter module is enabled and configured properly, as this directive only works within that context.
Using a value outside the range of 0-100 may lead to errors or unintended behavior in image processing.
Remember that setting a higher quality (close to 100) will generate larger file sizes, potentially impacting loading speeds.