if (null === $constraint->minWidth && null === $constraint->maxWidth
&& null === $constraint->minHeight && null === $constraint->maxHeight
+ && null === $constraint->minPixels && null === $constraint->maxPixels
&& null === $constraint->minRatio && null === $constraint->maxRatio
&& $constraint->allowSquare && $constraint->allowLandscape && $constraint->allowPortrait
&& !$constraint->detectCorrupted) {
$size = @getimagesize($value);
- if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
+ if (empty($size) || (0 === $size[0]) || (0 === $size[1])) {
$this->context->buildViolation($constraint->sizeNotDetectedMessage)
->setCode(Image::SIZE_NOT_DETECTED_ERROR)
->addViolation();
if ($constraint->minWidth) {
if (!ctype_digit((string) $constraint->minWidth)) {
- throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth));
+ throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width.', $constraint->minWidth));
}
if ($width < $constraint->minWidth) {
if ($constraint->maxWidth) {
if (!ctype_digit((string) $constraint->maxWidth)) {
- throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth));
+ throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width.', $constraint->maxWidth));
}
if ($width > $constraint->maxWidth) {
}
}
+ $pixels = $width * $height;
+
+ if (null !== $constraint->minPixels) {
+ if (!ctype_digit((string) $constraint->minPixels)) {
+ throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum amount of pixels', $constraint->minPixels));
+ }
+
+ if ($pixels < $constraint->minPixels) {
+ $this->context->buildViolation($constraint->minPixelsMessage)
+ ->setParameter('{{ pixels }}', $pixels)
+ ->setParameter('{{ min_pixels }}', $constraint->minPixels)
+ ->setParameter('{{ height }}', $height)
+ ->setParameter('{{ width }}', $width)
+ ->setCode(Image::TOO_FEW_PIXEL_ERROR)
+ ->addViolation();
+ }
+ }
+
+ if (null !== $constraint->maxPixels) {
+ if (!ctype_digit((string) $constraint->maxPixels)) {
+ throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum amount of pixels', $constraint->maxPixels));
+ }
+
+ if ($pixels > $constraint->maxPixels) {
+ $this->context->buildViolation($constraint->maxPixelsMessage)
+ ->setParameter('{{ pixels }}', $pixels)
+ ->setParameter('{{ max_pixels }}', $constraint->maxPixels)
+ ->setParameter('{{ height }}', $height)
+ ->setParameter('{{ width }}', $width)
+ ->setCode(Image::TOO_MANY_PIXEL_ERROR)
+ ->addViolation();
+ }
+ }
+
$ratio = round($width / $height, 2);
if (null !== $constraint->minRatio) {