/**
  * Validates the input.
  * 
  * @return     bool File is valid image according to given parameters.
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 protected function validate()
 {
     if (!parent::validate()) {
         return false;
     }
     $file = $this->getData($this->getArgument());
     $type = @getimagesize($file->getTmpName());
     if ($type === false) {
         $this->throwError('no_image');
         return false;
     }
     list($width, $height, $imageType) = $type;
     if ($this->hasParameter('max_width') && $width > $this->getParameter('max_width')) {
         $this->throwError('max_width');
         return false;
     }
     if ($this->hasParameter('min_width') && $width < $this->getParameter('min_width')) {
         $this->throwError('min_width');
         return false;
     }
     if ($this->hasParameter('max_height') && $height > $this->getParameter('max_height')) {
         $this->throwError('max_height');
         return false;
     }
     if ($this->hasParameter('min_height') && $height < $this->getParameter('min_height')) {
         $this->throwError('min_height');
         return false;
     }
     if (!$this->hasParameter('format')) {
         return true;
     }
     // We need this additional alias map because image_type_to_extension()
     // returns only "jpeg" but not "jpg" or "tiff" but not "tif"
     $aliases = array(IMAGETYPE_JPEG => 'jpg', IMAGETYPE_TIFF_II => 'tif', IMAGETYPE_TIFF_MM => 'tif');
     $ext = image_type_to_extension($imageType, false);
     $format = $this->getParameter('format', array());
     if (!is_array($format)) {
         $format = explode(' ', $this->getParameter('format'));
     }
     foreach ($format as $name) {
         $lName = strtolower($name);
         if ($ext == $lName) {
             return true;
         } elseif (isset($aliases[$imageType]) && $aliases[$imageType] == $name) {
             return true;
         }
     }
     $this->throwError('format');
     return false;
 }
 /**
  * Validates the input.
  * 
  * @return     bool File is valid image according to given parameters.
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 protected function validate()
 {
     if (!parent::validate()) {
         return false;
     }
     $file = $this->getData($this->getArgument());
     $type = @getimagesize($file->getTmpName());
     if ($type === false) {
         $this->throwError('no_image');
         return false;
     }
     list($width, $height, $imageType) = $type;
     if ($this->hasParameter('max_width') && $width > $this->getParameter('max_width')) {
         $this->throwError('max_width');
         return false;
     }
     if ($this->hasParameter('min_width') && $width < $this->getParameter('min_width')) {
         $this->throwError('min_width');
         return false;
     }
     if ($this->hasParameter('max_height') && $height > $this->getParameter('max_height')) {
         $this->throwError('max_height');
         return false;
     }
     if ($this->hasParameter('min_height') && $height < $this->getParameter('min_height')) {
         $this->throwError('min_height');
         return false;
     }
     if (!$this->hasParameter('format')) {
         return true;
     }
     $formats = array('gif' => IMAGETYPE_GIF, 'jpeg' => IMAGETYPE_JPEG, 'jpg' => IMAGETYPE_JPEG, 'png' => IMAGETYPE_PNG, 'bmp' => IMAGETYPE_BMP, 'psd' => IMAGETYPE_PSD, 'swf' => IMAGETYPE_SWF);
     $format = $this->getParameter('format', array());
     if (!is_array($format)) {
         $format = explode(' ', $this->getParameter('format'));
     }
     foreach ($format as $name) {
         if ($formats[strtolower($name)] == $imageType) {
             return true;
         }
     }
     $this->throwError('format');
     return false;
 }
예제 #3
0
 /**
  * Validates the input
  * 
  * @return     bool The file is valid according to given parameters.
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 protected function validate()
 {
     return parent::validate();
 }