Search
Varnish Cache Plus

Image

Description

VMOD image provides a tool for image modification and optimization.

VMOD image is available through the package varnish-plus-vmods-extras.

Examples

Convert to WebP

import image;
import headerplus;

sub vcl_backend_response {
	headerplus.init(beresp);
	if (beresp.http.content-type == "image/jpeg" ||
	    beresp.http.content-type == "image/png") {
		if (bereq.http.Accept ~ "image/webp") {
			image.webp();
		}
		headerplus.attr_set("Vary", "Accept");
	}
	headerplus.write();
}

Functions

webp

VOID webp([INT quality = 75], [INT resize_width], [INT resize_height], [BOOL lossless = false], [INT lossless_level = 6])

Convert an image to the WebP format and store it in cache. Optionally scale, resize or change the quality of conversion. Scaling is done by using only one of resize_width or resize_height. quality and lossless are mutually exclusive options. The supported content types to convert are image/png and image/jpeg. When called this function disables streaming. It should not be re-enabled for proper functionality.

Arguments

  • INT quality - The compression quality, between 0 and 100. A lower number will result in a smaller size but lower quality.
  • INT resize_width - Change the width of the converted image. Can scale the image to the width when only setting this parameter.
  • INT resize_height - Change the height of the converted image. Can scale the image to the height when only setting this parameter.
  • BOOL lossless - Enable lossless compression. When enabled quality is ignored and lossless_level is used instead.
  • INT lossless_level - Set the compression mode, between 0 and 9. A lower number is faster but produces a larger file size.

Returns

Nothing.