FileValidatorImage

This module implements ProcessWire’s FileValidator interface, which is used by

$sanitizer->validateFile() as part of ProcessWire’s built-in file validations. This is used by existing file uploads, for example. This module adds support for validation of common image bitmap formats: JPG, PNG, GIF.

Copyright 2020 by Ryan Cramer for ProcessWire 3.x

USAGE

You can use from $sanitizer
$valid = $sanitizer->validateFile('/path/to/file.jpg');
if($valid) {
valid image file
} else {
not valid image file
$reason = $sanitizer->errors('last string clear');
echo "Image not valid because: $reason";
}

You can use the module directly if you prefer
This is also useful if you want to specify min/max dimensions
$validator = $modules->get('FileValidatorImage');
$validator->minWidth = 400;
$validator->minHeight = 250;
$validator->maxWidth = 1920;
$validator->maxHeight = 1080;
if($validator->isValid('/path/to/file.jpg')) {
image is valid
} else {
$reason = $validator->getReason();
"Image not valid because: $reason";
}

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the FileValidatorImage class also inherits all the methods and properties of: FileValidatorModule, WireData and Wire.

Show class?     Show args?       Only hookable?    

Properties

NameReturnSummary 
FileValidatorImage::maxHeight int 
FileValidatorImage::maxWidth int 
FileValidatorImage::minHeight int 
FileValidatorImage::minWidth int 

Additional methods and properties

In addition to the methods and properties above, FileValidatorImage also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.269