ImageCropper
API reference › FilePond › file › ImageCropper
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.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | ImageCropper | |
crop() | Returns a copy of the file cropped to its EncodedFile::getCropRectangle() rectangle. | ImageCropper |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(int $maxPixels, int $maxDimension, int $maxInputBytes, int $quality = 90)Parameters
| Parameter | Type | Description |
|---|---|---|
$maxPixels | int | Maximum source pixel count before decoding. |
$maxDimension | int | Maximum source width or height, in pixels. |
$maxInputBytes | int | Maximum source byte count before header parsing. |
$quality | int | Output quality for lossy formats, from 0 to 100. |
Throws
InvalidArgumentException: if any processing limit is not positive.RuntimeException: if thegdextension is not loaded.
crop()
Section titled “crop() ”public function crop(yii2\extensions\filepond\file\EncodedFile $file): yii2\extensions\filepond\file\EncodedFileReturns 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
| Parameter | Type | Description |
|---|---|---|
$file | EncodedFile | Image 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.