FaceCompressor.compressWebpFromDetectedFace Method

Module: FaceCompressor

Definition

Crops an already detected face using a tighter, eye-distance-based face placement (different from the Bioseal portrait used by compress_ai_from_detected_face), resizes the crop to the given output size, and compresses it to WebP so that its size does not exceed the given byte budget.

Unlike compress_webp, no face detection is performed: the caller provides the face, which avoids running the FaceDetector model a second time when it has already been run on the image.

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. No model needs to be loaded to use this function, since the standard WebP codec is used directly.

Uint8List compressWebpFromDetectedFace(Image image, DetectedFace detectedFace, int outputWidth, int outputHeight, int byteBudget, double eyeImageWidthRatio, double eyeImageHeightRatio, double imageRatio)

Parameters

image Image
in Source image the face was detected in.

detectedFace DetectedFace
in Face to compress, as previously returned by a FaceDetector. It must be expressed in the coordinate system of ‘image’: if it was detected on a downscaled copy, rescale it back with DetectedFace.rescale() first.

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.