FaceCompressor.compressWebp Method

Module: FaceCompressor

Definition

Detects the largest face in an image, crops it using a tighter, eye-distance-based face placement (different from the Bioseal portrait used by compress_ai), resizes the crop to the given output size, and compresses it to WebP so that its size does not exceed the given byte budget.

The WebP quality is searched automatically to find the highest quality whose encoded size fits within byte_budget. If even the lowest quality does not fit, the function fails and no data is returned.

Important

The input image must be in 24-bit BGR format. Loading a FaceDetector model is required to use this function. Unlike compress_ai, no compression model needs to be loaded since the standard WebP codec is used directly.

Uint8List compressWebp(Image image, int outputWidth, int outputHeight, int byteBudget, double eyeImageWidthRatio, double eyeImageHeightRatio, double imageRatio)

Parameters

image Image
in Source image containing a face to detect and compress.

outputWidth int
in Width in pixels of the cropped portrait to compress. Default recommended value is 84.

outputHeight int
in Height in pixels of the cropped portrait to compress. Default recommended value is 112.

byteBudget int
in Maximum size in bytes of the compressed WebP buffer. Default recommended value is 800.

eyeImageWidthRatio double
in Ratio between eye distance and crop width, forwarded to DetectedFace.getPortraitBounds() to compute the face placement. Must be in the range ]0;1[. Default recommended value is 0.40.

eyeImageHeightRatio double
in Ratio between eye distance to top and crop height, forwarded to DetectedFace.getPortraitBounds() to compute the face placement. Must be in the range ]0;1[. Default recommended value is 0.45.

imageRatio double
in Ratio between crop height and crop width, forwarded to DetectedFace.getPortraitBounds() to compute the face placement. Default recommended value is 1.3333334 (4/3).

Returns

Uint8List
Buffer that receives the WebP-compressed image, whose size will not exceed byte_budget.

Exceptions

An error has occurred during Face Library execution.