- if ($this->context instanceof ExecutionContextInterface) {
- $this->context->buildViolation($constraint->allowPortraitMessage)
- ->setParameter('{{ width }}', $width)
- ->setParameter('{{ height }}', $height)
- ->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
- ->addViolation();
- } else {
- $this->buildViolation($constraint->allowPortraitMessage)
- ->setParameter('{{ width }}', $width)
- ->setParameter('{{ height }}', $height)
- ->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
+ $this->context->buildViolation($constraint->allowPortraitMessage)
+ ->setParameter('{{ width }}', $width)
+ ->setParameter('{{ height }}', $height)
+ ->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
+ ->addViolation();
+ }
+
+ if ($constraint->detectCorrupted) {
+ if (!function_exists('imagecreatefromstring')) {
+ throw new RuntimeException('Corrupted images detection requires installed and enabled GD extension');
+ }
+
+ $resource = @imagecreatefromstring(file_get_contents($value));
+
+ if (false === $resource) {
+ $this->context->buildViolation($constraint->corruptedMessage)
+ ->setCode(Image::CORRUPTED_IMAGE_ERROR)