Skip to content
PHP Ecosystem
Explore

ImageCropper

API reference › FilePond › file › ImageCropper

final readonly classyii2\extensions\filepond\file\ImageCropper
Sourcesrc/file/ImageCropper.php

Applies the crop rectangle stored by the Cropper.js editor to an image on the server with GD.

Use it when the Image Transform plugin is disabled, so the browser uploads the original image and the server produces the cropped file from metadata.crop.rect. JPEG orientation metadata is honored before cropping when the exif extension is available, matching the orientation the editor displayed. Source byte, axis, and pixel limits are required; configure them from the application’s processing budget. They do not impose a hard process-memory cap.

MethodDescriptionDefined by
__construct()ImageCropper
crop()Returns a copy of the file cropped to its EncodedFile::getCropRectangle() rectangle.ImageCropper
public function __construct(int $maxPixels, int $maxDimension, int $maxInputBytes, int $quality = 90)

Parameters

ParameterTypeDescription
$maxPixelsintMaximum source pixel count before decoding.
$maxDimensionintMaximum source width or height, in pixels.
$maxInputBytesintMaximum source byte count before header parsing.
$qualityintOutput quality for lossy formats, from 0 to 100.

Throws

public function crop(yii2\extensions\filepond\file\EncodedFile $file): yii2\extensions\filepond\file\EncodedFile

Returns a copy of the file cropped to its EncodedFile::getCropRectangle() rectangle.

The rectangle is intersected with the image bounds, keeping at least the nearest edge pixel when they do not overlap. GIF, JPEG, PNG, and WebP keep their format; other formats, such as BMP, are encoded as PNG and the copy receives the image/png type and a .png extension. Files without a rectangle are returned unchanged.

Parameters

ParameterTypeDescription
$fileEncodedFileImage file carrying crop metadata.

Returns

EncodedFile: Cropped copy, or the same instance when no crop rectangle is present.

Throws

  • RuntimeException: if the source exceeds a processing limit or cannot be decoded or encoded.