Create a thumbnail after uploading an image through a form in a Symfony3 project
Using composer :
composer require weysan/doctrine-img-bundle
Enable the bundle in the app\AppKernel.php :
$bundles = array( ..., new Weysan\DoctrineImgBundle\WeysanDoctrineImgBundle(), ..., );
Import the configuration file in your app\config\config.yml :
imports: - { resource: "@WeysanDoctrineImgBundle/Resources/config/config.yml" } - { resource: "@WeysanDoctrineImgBundle/Resources/config/services.yml" }
You can specify where the public directory is in your config.yml file :
weysan_doctrine_img: public_root: %kernel.root_dir%/../web/
Create your doctrine entity, and put the annotation :
@ImgResize("image", width="500", height="300", uploadDir="media/upload/article", uploadDirDate=true, saveField="path", strict=true, crop=false)
- image : the field where you put the annotation
- width : the thumbnail's width
- height : the thumbnail's height
- strict : (true or false, default is true) if strict is true, the thumbnail will have the strict height and width. If strict is false, then the height and width will be the maximum size of the saved thumbnail.
- crop : (true or false, default is false) Would you like that the thumbnail could be cropped (interesting if strict is set to true)
- uploadDir : the directory where to put the thumbnail (in the public directory)
- uploadDirDate : (true or false, default is false) if the directory manages folders by date (uploadDir/YYYY/MM/). The folder must be existing.
- saveField : the entity's field where to save the thumbnail's name