Skip to content

Fit: fit#

The fit parameter in image processing determines how the image should be resized to meet the specified dimensions. There are several options for the fit parameter:

  1. clip: This is the default option. When an image dimension is specified using the h and w parameters, the image is resized to the supplied dimensions while other dimensions are altered to maintain the aspect ratio of the input image.
  2. crop: The image is resized to fit the supplied dimensions and any excess is cropped. Both h and w must be set.
  3. facearea: This option finds the area around faces in the image and scales it to the specified h and w dimensions.
  4. fill: The image is resized to fit within the specified h and w dimensions while preserving the original aspect ratio. Excess space is filled with a solid color. The resulting image matches the specified dimensions.
  5. max: The image is resized so that the larger dimension matches the specified dimension, while the other dimension is resized to maintain the aspect ratio.

fit=clip#

This is the default option when an image dimension is specified using the h and w parameters. The image is resized to the supplied dimensions while other dimensions are altered to maintain the aspect ratio of the input image.

fit=crop#

The image is resized to fit the supplied image dimensions and crops any excess. Both h and w needs to be set.

fit=facearea#

Finds the area around faces in an image and scales it to specified width and height dimensions.

fit=fill#

The image is resized to fit within the requested h and w dimensions while preserving the original aspect ratio. Excess space is filled with a solid color. The resulting image matches the supplied dimensions.

Height: h#

h controls the height of the output image in pixels. If only a single dimension is specified, the aspect ratio will be maintained based on the aspect ratio of the input image.

Width: w#

w controls the width of the output image in pixels. If only a single dimension is specified, the aspect ratio will be maintained based on the aspect ratio of the input image.

DPR: dpr#

dpr controls the device-pixel ratio. The dpr parameter causes the w parameters to be treated as device independent pixels (also known as “CSS pixels”). A 400×300 image at dpr=2 will actually be a 800×600 pixel image.