I have a symfony form, where i upload images. Allowed types are jpeg and svg. When i added validation for maxWidth and maxHeight on jpeg works correctly, but on svg I get form error The size of the image could not be detected.
(https://symfony.com/doc/5.x/reference/constraints/Image.html#sizenotdetectedmessage). I tried with many svg images and still the same error. Without the validation, they are uploading and rendered correctly on the template, so the images are not broken. What can i do to validate the width and height of the svg image? Here is the code of the form:
$builder
->add('image', FileType::class, [
'required' => false,
'multiple' => true,
'mapped' => false,
'constraints' => [
new NotBlank([
'message' => 'image-cannot-be-blank',
'groups' => 'required_image'
]),
new All([
'constraints' => [
new Image([
'maxSize' => '6M',
'maxWidth' => 800,
'maxHeight' => 800,
'mimeTypes' => [
'image/jpeg',
'image/svg+xml',
],
'mimeTypesMessage' => 'please-upload-valid-image',
])
]])
],
'attr' => ['accept' => 'image/jpeg, image/svg+xml']
])