weysan/doctrine-img-bundle

Helper to create thumbnails thanks to doctrine annotation in a doctrine entity

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.2-beta 2016-07-25 09:02 UTC

This package is not auto-updated.

Last update: 2023-02-04 09:23:52 UTC


README

Create a thumbnail after uploading an image through a form in a Symfony3 project

Install the bundle

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/

How to use it ?

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