title: What kind of library to make or use in order to resize an Image by reasing Symfony 3.0 config
body: <p>Hello fellows I on my asympfony 3.0 project I want to make a Library that when is constructed to read from config.yml these parameters:</p>
  
  <ul>
  <li>max_width</li>
  <li>max_height</li>
  </ul>
  
  <p>And the library will read them and will perfom a image resize to these dimentions provided by config.yml or any other way to read config.</p>
  
  <p>In order to be more clear I have this Entity:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Filesystem\Filesystem;
  
  /**
  * @ORM\Entity
  * @ORM\Table(name="images")
  * @ORM\Entity(repositoryClass="AppBundle\Entity\ImagesRepository")
  * @ORM\HasLifecycleCallbacks
  */
  class Images
  {
      /**
       * @ORM\Column(type="string", length=60)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="CUSTOM")
       * @ORM\CustomIdGenerator(class="AppBundle\Doctrine\AutoIdGenerate")
       */
      private $id;
  
      /**
      * Filename of the Image
      * @ORM\Column(type="string", length=100)
      */
      private $name;
  
      /**
      * Filename of the Thumbnail
      * @ORM\Column(type="string", length=100)
      */
      private $name_small;
  
      /**
      * ImageGroup og the Image
      * @ORM\ManyToOne(targetEntity="AppBundle\Entity\ImageGroups", inversedBy="images")
      */
      private $group;
  
  
      /**
       * @Assert\File(maxSize="20000000")
       */
      private $file;
  
      private $upload_dir='images';
      private $temp;
  
      /**
       * Get file.
       *
       * @return UploadedFile
       */
      public function getFile()
      {
          return $this-&gt;file;
      }
  
      /**
       * Sets file.
       *
       * @param UploadedFile $file
       */
      public function setFile(UploadedFile $file,$upload_dir)
      {
          $this-&gt;file = $file;
  
          // check if we have an old image path
          if (isset($this-&gt;name))
          {
              // store the old name to delete after the update
              $this-&gt;temp = $this-&gt;name;
              $this-&gt;name = null;
          }
          else
          {
              $this-&gt;name = sha1(uniqid(mt_rand(), true)).'.'.$file-&gt;guessExtension();
          }
  
          $this-&gt;name_small="small_".$this-&gt;name;
          $this-&gt;upload_dir=$upload_dir;
  
          return $this;
      }
  
      /**
       * @ORM\PrePersist()
       * @ORM\PreUpdate()
       */
      public function preUpload()
      {
          if (null !== $this-&gt;getFile())
          {
              // do whatever you want to generate a unique name
              $filename = sha1(uniqid(mt_rand(), true));
              $this-&gt;name = $filename.'.'.$this-&gt;getFile()-&gt;guessExtension();
              $this-&gt;name_small='small_'.$this-&gt;name;
          }
      }
  
      /**
      *Getting the directory that will upload the file
      */
      public function getUploadRootDir()
      {
        $dir= __DIR__.'/../../../web/'.$this-&gt;upload_dir;
        return $dir;
      }
  
  
      /**
       * @ORM\PostPersist()
       * @ORM\PostUpdate()
       */
      public function upload()
      {
          if (null === $this-&gt;getFile())
          {
              return;
          }
  
          // if there is an error when moving the file, an exception will
          // be automatically thrown by move(). This will properly prevent
          // the entity from being persisted to the database on error
  
          //-- Make the Thumbnail Here --
  
          $dir=$this-&gt;getUploadRootDir();
  
          $fs = new Filesystem();
  
          if(!$fs-&gt;exists($dir))
          {
            $fs-&gt;mkdir($dir,0777,true);
          }
  
          $file=$this-&gt;getFile();
          $file-&gt;move($dir, $this-&gt;name);
  
          // check if we have an old image
          if (isset($this-&gt;temp))
          {
              // delete the old image
              unlink($this-&gt;getUploadRootDir().'/'.$this-&gt;temp);
              // clear the temp image path
              $this-&gt;temp = null;
          }
          $this-&gt;file = null;
      }
  
      /**
       * @ORM\PostRemove()
       */
      public function removeUpload()
      {
          $file = $this-&gt;getUploadRootDir();
  
          error_reporting(E_ERROR | E_PARSE); //If the file does not exist just ingore the warning
  
          if (file_exists($file.'/'.$this-&gt;name)===true)
          {
              unlink($file.'/'.$this-&gt;name);
          }
  
          if(file_exists($file.'/'.$this-&gt;name_small)===true);
          {
            unlink($file.'/'.$this-&gt;name_small);
          }
  
          error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);//But we want warnings back
      }
  
  
      /**
       * Get id
       *
       * @return string
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
  
      /**
       * Get name
       *
       * @return string
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * Get nameSmall
       *
       * @return string
       */
      public function getNameSmall()
      {
          return $this-&gt;name_small;
      }
  
      /**
       * Set group
       *
       * @param \AppBundle\Entity\ImageGroups $group
       *
       * @return Images
       */
      public function setGroup(\AppBundle\Entity\ImageGroups $group = null)
      {
          $this-&gt;group = $group;
  
          return $this;
      }
  
      /**
       * Get group
       *
       * @return \AppBundle\Entity\ImageGroups
       */
      public function getGroup()
      {
          return $this-&gt;group;
      }
  
      /**
       * Set name
       *
       * @param string $name
       *
       * @return Images
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Set nameSmall
       *
       * @param string $nameSmall
       *
       * @return Images
       */
      public function setNameSmall($nameSmall)
      {
          $this-&gt;name_small = $nameSmall;
  
          return $this;
      }
  }
  </code></pre>
  
  <p>As you can see the entity above has Doctrine triggers. Inside function upload I want to call:</p>
  
  <pre><code>new ImageProcessor($image_path,$extention)-&gt;to_thumb($filename) 
  </code></pre>
  
  <p>And this will read from config.yml the max_width and max_height and will perform the image resize. The ImageProcessor will be the library that will do any kind of image processings like crop, resize, etc etc.</p>
  
  <p>The problem is NOT how to resize the image but on how can I make this Library resubable and easily configurable by config.yml. I cannot find a good tutorial or manual to do that.</p>