Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

New in Symfony 2.4: A more powerful image validator

Contributed by
Luciano Mammino
in #8490.

When using a file upload input on an HTML page to allow images to be uploaded, you should use the Image constraint instead of the more generic File one. Besides restricting the allowed mime-types, it exposes additional options specific to images like validating the image height or their width.

And as of Symfony 2.4, you can also validate the image aspect ratio (defined as width / height) and selectively allow square, landscape, and portrait image orientations with the new maxRatio, minRatio, allowSquare, allowLandscape, and allowPortrait options.

Read the Image constraint documentation page for more information.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 2.4: A more powerful image validator symfony.com/blog/new-in-symfony-2-4-a-more-powerful-image-validator

Tweet this

Comments

Great !!
Very useful addition as a core feature.
Nice feature :)
+1 for this change :)
nice addition to core
Cool !!
So happy this feature has been appreciated :)
Very nice!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.