biffbangpow / silverstripe-imagesize-validator
Validates the dimensions of an image during upload
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
This package is auto-updated.
Last update: 2024-10-30 02:21:41 UTC
README
This extends the standard upload validator and provides additional checks on the dimensions of an uploaded image.
The validator can be applied directly to an uploadfield:
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab('Root.Main', [ UploadField::create('Image')->setValidator(PixelSizeValidator::create()), ]); return $fields; }
Note: the validator should only be added to upload fields where the underlying class is an Image
or subclass thereof. Adding the validator to an upload field where files may be uploaded will cause any non-images to be rejected.
By default the validator will reject an image which has a pixel dimension greater than 2000 in either axis. This can be overidden in yml config, eg:
--- Name: bbppixelsizevalidator --- BiffBangPow\Validators\PixelSizeValidator: max_width: 2500 max_height: 1200