class Image
Same name in this branch
- 11.1.x vendor/symfony/dom-crawler/Image.php \Symfony\Component\DomCrawler\Image
- 11.1.x core/lib/Drupal/Core/Image/Image.php \Drupal\Core\Image\Image
- 11.1.x core/lib/Drupal/Component/Utility/Image.php \Drupal\Component\Utility\Image
- 11.1.x core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image
- 11.1.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Image.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image
Validates that a file (or a path to a file) is a valid image.
@author Benjamin Dulau <benjamin.dulau@gmail.com> @author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Constraint
Expanded class hierarchy of Image
1 file declares its use of Image
- ConstraintManager.php in core/
lib/ Drupal/ Core/ Validation/ ConstraintManager.php
129 string references to 'Image'
- banner.component.yml in core/
profiles/ demo_umami/ themes/ umami/ components/ banner/ banner.component.yml - core/profiles/demo_umami/themes/umami/components/banner/banner.component.yml
- BrowserKitDriver::canSubmitForm in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - BrowserKitDriver::getFormField in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - Returns form field from XPath query.
- BrowserKitDriver::getValue in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - Returns element's value by its XPath query.
- BrowserKitDriver::mergeForms in vendor/
behat/ mink-browserkit-driver/ src/ BrowserKitDriver.php - Merges second form values into first one.
File
-
vendor/
symfony/ validator/ Constraints/ Image.php, line 20
Namespace
Symfony\Component\Validator\ConstraintsView source
class Image extends File {
public const SIZE_NOT_DETECTED_ERROR = '6d55c3f4-e58e-4fe3-91ee-74b492199956';
public const TOO_WIDE_ERROR = '7f87163d-878f-47f5-99ba-a8eb723a1ab2';
public const TOO_NARROW_ERROR = '9afbd561-4f90-4a27-be62-1780fc43604a';
public const TOO_HIGH_ERROR = '7efae81c-4877-47ba-aa65-d01ccb0d4645';
public const TOO_LOW_ERROR = 'aef0cb6a-c07f-4894-bc08-1781420d7b4c';
public const TOO_FEW_PIXEL_ERROR = '1b06b97d-ae48-474e-978f-038a74854c43';
public const TOO_MANY_PIXEL_ERROR = 'ee0804e8-44db-4eac-9775-be91aaf72ce1';
public const RATIO_TOO_BIG_ERROR = '70cafca6-168f-41c9-8c8c-4e47a52be643';
public const RATIO_TOO_SMALL_ERROR = '59b8c6ef-bcf2-4ceb-afff-4642ed92f12e';
public const SQUARE_NOT_ALLOWED_ERROR = '5d41425b-facb-47f7-a55a-de9fbe45cb46';
public const LANDSCAPE_NOT_ALLOWED_ERROR = '6f895685-7cf2-4d65-b3da-9029c5581d88';
public const PORTRAIT_NOT_ALLOWED_ERROR = '65608156-77da-4c79-a88c-02ef6d18c782';
public const CORRUPTED_IMAGE_ERROR = '5d4163f3-648f-4e39-87fd-cc5ea7aad2d1';
// Include the mapping from the base class
protected const ERROR_NAMES = [
self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR',
self::NOT_READABLE_ERROR => 'NOT_READABLE_ERROR',
self::EMPTY_ERROR => 'EMPTY_ERROR',
self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
self::INVALID_MIME_TYPE_ERROR => 'INVALID_MIME_TYPE_ERROR',
self::FILENAME_TOO_LONG => 'FILENAME_TOO_LONG',
self::SIZE_NOT_DETECTED_ERROR => 'SIZE_NOT_DETECTED_ERROR',
self::TOO_WIDE_ERROR => 'TOO_WIDE_ERROR',
self::TOO_NARROW_ERROR => 'TOO_NARROW_ERROR',
self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR',
self::TOO_LOW_ERROR => 'TOO_LOW_ERROR',
self::TOO_FEW_PIXEL_ERROR => 'TOO_FEW_PIXEL_ERROR',
self::TOO_MANY_PIXEL_ERROR => 'TOO_MANY_PIXEL_ERROR',
self::RATIO_TOO_BIG_ERROR => 'RATIO_TOO_BIG_ERROR',
self::RATIO_TOO_SMALL_ERROR => 'RATIO_TOO_SMALL_ERROR',
self::SQUARE_NOT_ALLOWED_ERROR => 'SQUARE_NOT_ALLOWED_ERROR',
self::LANDSCAPE_NOT_ALLOWED_ERROR => 'LANDSCAPE_NOT_ALLOWED_ERROR',
self::PORTRAIT_NOT_ALLOWED_ERROR => 'PORTRAIT_NOT_ALLOWED_ERROR',
self::CORRUPTED_IMAGE_ERROR => 'CORRUPTED_IMAGE_ERROR',
];
public array|string $mimeTypes = 'image/*';
public ?int $minWidth = null;
public ?int $maxWidth = null;
public ?int $maxHeight = null;
public ?int $minHeight = null;
public int|float|null $maxRatio = null;
public int|float|null $minRatio = null;
public int|float|null $minPixels = null;
public int|float|null $maxPixels = null;
public bool $allowSquare = true;
public bool $allowLandscape = true;
public bool $allowPortrait = true;
public bool $detectCorrupted = false;
// The constant for a wrong MIME type is taken from the parent class.
public string $mimeTypesMessage = 'This file is not a valid image.';
public string $sizeNotDetectedMessage = 'The size of the image could not be detected.';
public string $maxWidthMessage = 'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.';
public string $minWidthMessage = 'The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.';
public string $maxHeightMessage = 'The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.';
public string $minHeightMessage = 'The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.';
public string $minPixelsMessage = 'The image has too few pixels ({{ pixels }} pixels). Minimum amount expected is {{ min_pixels }} pixels.';
public string $maxPixelsMessage = 'The image has too many pixels ({{ pixels }} pixels). Maximum amount expected is {{ max_pixels }} pixels.';
public string $maxRatioMessage = 'The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.';
public string $minRatioMessage = 'The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.';
public string $allowSquareMessage = 'The image is square ({{ width }}x{{ height }}px). Square images are not allowed.';
public string $allowLandscapeMessage = 'The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.';
public string $allowPortraitMessage = 'The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.';
public string $corruptedMessage = 'The image file is corrupted.';
/**
* @param array<string,mixed>|null $options
* @param positive-int|string|null $maxSize The max size of the underlying file
* @param bool|null $binaryFormat Pass true to use binary-prefixed units (KiB, MiB, etc.) or false to use SI-prefixed units (kB, MB) in displayed messages. Pass null to guess the format from the maxSize option. (defaults to null)
* @param non-empty-string[]|null $mimeTypes Acceptable media types
* @param positive-int|null $filenameMaxLength Maximum length of the file name
* @param string|null $disallowEmptyMessage Enable empty upload validation with this message in case of error
* @param string|null $uploadIniSizeErrorMessage Message if the file size exceeds the max size configured in php.ini
* @param string|null $uploadFormSizeErrorMessage Message if the file size exceeds the max size configured in the HTML input field
* @param string|null $uploadPartialErrorMessage Message if the file is only partially uploaded
* @param string|null $uploadNoTmpDirErrorMessage Message if there is no upload_tmp_dir in php.ini
* @param string|null $uploadCantWriteErrorMessage Message if the uploaded file can not be stored in the temporary directory
* @param string|null $uploadErrorMessage Message if an unknown error occurred on upload
* @param string[]|null $groups
* @param int<0, int>|null $minWidth Minimum image width
* @param positive-int|null $maxWidth Maximum image width
* @param positive-int|null $maxHeight Maximum image height
* @param int<0, int>|null $minHeight Minimum image weight
* @param positive-int|float|null $maxRatio Maximum image ratio
* @param int<0, max>|float|null $minRatio Minimum image ration
* @param int<0, max>|float|null $minPixels Minimum amount of pixels
* @param positive-int|float|null $maxPixels Maximum amount of pixels
* @param bool|null $allowSquare Whether to allow a square image (defaults to true)
* @param bool|null $allowLandscape Whether to allow a landscape image (defaults to true)
* @param bool|null $allowPortrait Whether to allow a portrait image (defaults to true)
* @param bool|null $detectCorrupted Whether to validate the image is not corrupted (defaults to false)
* @param string|null $sizeNotDetectedMessage Message if the system can not determine image size and there is a size constraint to validate
*
* @see https://www.iana.org/assignments/media-types/media-types.xhtml Existing media types
*/
public function __construct(?array $options = null, int|string|null $maxSize = null, ?bool $binaryFormat = null, ?array $mimeTypes = null, ?int $filenameMaxLength = null, ?int $minWidth = null, ?int $maxWidth = null, ?int $maxHeight = null, ?int $minHeight = null, int|float|null $maxRatio = null, int|float|null $minRatio = null, int|float|null $minPixels = null, int|float|null $maxPixels = null, ?bool $allowSquare = null, ?bool $allowLandscape = null, ?bool $allowPortrait = null, ?bool $detectCorrupted = null, ?string $notFoundMessage = null, ?string $notReadableMessage = null, ?string $maxSizeMessage = null, ?string $mimeTypesMessage = null, ?string $disallowEmptyMessage = null, ?string $filenameTooLongMessage = null, ?string $uploadIniSizeErrorMessage = null, ?string $uploadFormSizeErrorMessage = null, ?string $uploadPartialErrorMessage = null, ?string $uploadNoFileErrorMessage = null, ?string $uploadNoTmpDirErrorMessage = null, ?string $uploadCantWriteErrorMessage = null, ?string $uploadExtensionErrorMessage = null, ?string $uploadErrorMessage = null, ?string $sizeNotDetectedMessage = null, ?string $maxWidthMessage = null, ?string $minWidthMessage = null, ?string $maxHeightMessage = null, ?string $minHeightMessage = null, ?string $minPixelsMessage = null, ?string $maxPixelsMessage = null, ?string $maxRatioMessage = null, ?string $minRatioMessage = null, ?string $allowSquareMessage = null, ?string $allowLandscapeMessage = null, ?string $allowPortraitMessage = null, ?string $corruptedMessage = null, ?array $groups = null, mixed $payload = null) {
parent::__construct($options, $maxSize, $binaryFormat, $mimeTypes, $filenameMaxLength, $notFoundMessage, $notReadableMessage, $maxSizeMessage, $mimeTypesMessage, $disallowEmptyMessage, $filenameTooLongMessage, $uploadIniSizeErrorMessage, $uploadFormSizeErrorMessage, $uploadPartialErrorMessage, $uploadNoFileErrorMessage, $uploadNoTmpDirErrorMessage, $uploadCantWriteErrorMessage, $uploadExtensionErrorMessage, $uploadErrorMessage, $groups, $payload);
$this->minWidth = $minWidth ?? $this->minWidth;
$this->maxWidth = $maxWidth ?? $this->maxWidth;
$this->maxHeight = $maxHeight ?? $this->maxHeight;
$this->minHeight = $minHeight ?? $this->minHeight;
$this->maxRatio = $maxRatio ?? $this->maxRatio;
$this->minRatio = $minRatio ?? $this->minRatio;
$this->minPixels = $minPixels ?? $this->minPixels;
$this->maxPixels = $maxPixels ?? $this->maxPixels;
$this->allowSquare = $allowSquare ?? $this->allowSquare;
$this->allowLandscape = $allowLandscape ?? $this->allowLandscape;
$this->allowPortrait = $allowPortrait ?? $this->allowPortrait;
$this->detectCorrupted = $detectCorrupted ?? $this->detectCorrupted;
$this->sizeNotDetectedMessage = $sizeNotDetectedMessage ?? $this->sizeNotDetectedMessage;
$this->maxWidthMessage = $maxWidthMessage ?? $this->maxWidthMessage;
$this->minWidthMessage = $minWidthMessage ?? $this->minWidthMessage;
$this->maxHeightMessage = $maxHeightMessage ?? $this->maxHeightMessage;
$this->minHeightMessage = $minHeightMessage ?? $this->minHeightMessage;
$this->minPixelsMessage = $minPixelsMessage ?? $this->minPixelsMessage;
$this->maxPixelsMessage = $maxPixelsMessage ?? $this->maxPixelsMessage;
$this->maxRatioMessage = $maxRatioMessage ?? $this->maxRatioMessage;
$this->minRatioMessage = $minRatioMessage ?? $this->minRatioMessage;
$this->allowSquareMessage = $allowSquareMessage ?? $this->allowSquareMessage;
$this->allowLandscapeMessage = $allowLandscapeMessage ?? $this->allowLandscapeMessage;
$this->allowPortraitMessage = $allowPortraitMessage ?? $this->allowPortraitMessage;
$this->corruptedMessage = $corruptedMessage ?? $this->corruptedMessage;
if (!\in_array('image/*', (array) $this->mimeTypes, true) && !\array_key_exists('mimeTypesMessage', $options ?? []) && null === $mimeTypesMessage) {
$this->mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.';
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Constraint::$groups | public | property | The groups that the constraint belongs to. | ||
Constraint::$payload | public | property | Domain-specific data attached to a constraint. | ||
Constraint::addImplicitGroupName | public | function | Adds the given group if this constraint is in the Default group. | 2 | |
Constraint::CLASS_CONSTRAINT | public | constant | Marks a constraint that can be put onto classes. | ||
Constraint::DEFAULT_GROUP | public | constant | The name of the group given to all constraints with no explicit group. | ||
Constraint::getDefaultOption | public | function | Returns the name of the default option. | 28 | |
Constraint::getErrorName | public static | function | Returns the name of the given error code. | ||
Constraint::getRequiredOptions | public | function | Returns the name of the required options. | 22 | |
Constraint::getTargets | public | function | Returns whether the constraint can be put onto classes, properties or both. |
8 | |
Constraint::normalizeOptions | protected | function | |||
Constraint::PROPERTY_CONSTRAINT | public | constant | Marks a constraint that can be put onto properties. | ||
Constraint::validatedBy | public | function | Returns the name of the class that validates this constraint. | 9 | |
Constraint::__sleep | public | function | Optimizes the serialized value to minimize storage space. | ||
File::$binaryFormat | public | property | |||
File::$disallowEmptyMessage | public | property | |||
File::$extensions | public | property | |||
File::$extensionsMessage | public | property | |||
File::$filenameMaxLength | public | property | |||
File::$filenameTooLongMessage | public | property | |||
File::$maxSize | protected | property | |||
File::$maxSizeMessage | public | property | |||
File::$notFoundMessage | public | property | |||
File::$notReadableMessage | public | property | |||
File::$uploadCantWriteErrorMessage | public | property | |||
File::$uploadErrorMessage | public | property | |||
File::$uploadExtensionErrorMessage | public | property | |||
File::$uploadFormSizeErrorMessage | public | property | |||
File::$uploadIniSizeErrorMessage | public | property | |||
File::$uploadNoFileErrorMessage | public | property | |||
File::$uploadNoTmpDirErrorMessage | public | property | |||
File::$uploadPartialErrorMessage | public | property | |||
File::EMPTY_ERROR | public | constant | |||
File::FILENAME_TOO_LONG | public | constant | |||
File::INVALID_EXTENSION_ERROR | public | constant | |||
File::INVALID_MIME_TYPE_ERROR | public | constant | |||
File::normalizeBinaryFormat | private | function | |||
File::NOT_FOUND_ERROR | public | constant | |||
File::NOT_READABLE_ERROR | public | constant | |||
File::TOO_LARGE_ERROR | public | constant | |||
File::__get | public | function | Returns the value of a lazily initialized option. | Overrides Constraint::__get | |
File::__isset | public | function | Overrides Constraint::__isset | ||
File::__set | public | function | Sets the value of a lazily initialized option. | Overrides Constraint::__set | |
Image::$allowLandscape | public | property | |||
Image::$allowLandscapeMessage | public | property | |||
Image::$allowPortrait | public | property | |||
Image::$allowPortraitMessage | public | property | |||
Image::$allowSquare | public | property | |||
Image::$allowSquareMessage | public | property | |||
Image::$corruptedMessage | public | property | |||
Image::$detectCorrupted | public | property | |||
Image::$maxHeight | public | property | |||
Image::$maxHeightMessage | public | property | |||
Image::$maxPixels | public | property | |||
Image::$maxPixelsMessage | public | property | |||
Image::$maxRatio | public | property | |||
Image::$maxRatioMessage | public | property | |||
Image::$maxWidth | public | property | |||
Image::$maxWidthMessage | public | property | |||
Image::$mimeTypes | public | property | Overrides File::$mimeTypes | ||
Image::$mimeTypesMessage | public | property | Overrides File::$mimeTypesMessage | ||
Image::$minHeight | public | property | |||
Image::$minHeightMessage | public | property | |||
Image::$minPixels | public | property | |||
Image::$minPixelsMessage | public | property | |||
Image::$minRatio | public | property | |||
Image::$minRatioMessage | public | property | |||
Image::$minWidth | public | property | |||
Image::$minWidthMessage | public | property | |||
Image::$sizeNotDetectedMessage | public | property | |||
Image::CORRUPTED_IMAGE_ERROR | public | constant | |||
Image::ERROR_NAMES | protected | constant | Maps error codes to the names of their constants. | Overrides File::ERROR_NAMES | |
Image::LANDSCAPE_NOT_ALLOWED_ERROR | public | constant | |||
Image::PORTRAIT_NOT_ALLOWED_ERROR | public | constant | |||
Image::RATIO_TOO_BIG_ERROR | public | constant | |||
Image::RATIO_TOO_SMALL_ERROR | public | constant | |||
Image::SIZE_NOT_DETECTED_ERROR | public | constant | |||
Image::SQUARE_NOT_ALLOWED_ERROR | public | constant | |||
Image::TOO_FEW_PIXEL_ERROR | public | constant | |||
Image::TOO_HIGH_ERROR | public | constant | |||
Image::TOO_LOW_ERROR | public | constant | |||
Image::TOO_MANY_PIXEL_ERROR | public | constant | |||
Image::TOO_NARROW_ERROR | public | constant | |||
Image::TOO_WIDE_ERROR | public | constant | |||
Image::__construct | public | function | Overrides File::__construct |