/**
  * Check dimensions, perform resize and then call parent validator.
  * 
  * @param array $value
  * @return sfValidatedFile
  */
 protected function doClean($value)
 {
     $file = parent::doClean($value);
     // resize the image by default
     if ($this->getOption('resize')) {
         // first of all, resize to given maximum and/or width but check for exception
         // if unsupported file format
         // FIXME this isn't elegant and should fail better (mime_types check should fail first before resize attempted)
         try {
             $image = new ImageTransform($file->getTempName(), $file->getType());
             $image->fit($this->getOption('max_width'), $this->getOption('max_height'));
             $image->save($file->getTempName());
         } catch (Exception $e) {
             // do nothing
         }
     } else {
         // fetch image info
         list($width, $height, $type, $attr) = getimagesize($file->getTempName());
         // do we have some exact required dimensions?
         if ($this->getOption('required_width') !== false || $this->getOption('required_height') !== false) {
             $passes_width = ($required_width = $this->getOption('required_width')) ? $width == $required_width : true;
             $passes_height = ($required_height = $this->getOption('required_height')) ? $height == $required_height : true;
             if (!$passes_height || !$passes_width) {
                 throw new sfValidatorError($this, 'required_dimensions', array('width' => $width, 'height' => $height, 'required_width' => $required_width, 'required_height' => $required_height));
             }
         }
         // check both dimensions to show useful error about both width and height if needed
         if ($width > $this->getOption('max_width') && $height > $this->getOption('max_height')) {
             throw new sfValidatorError($this, 'max_dimensions', array('width' => $width, 'height' => $height, 'max_width' => $this->getOption('max_width'), 'max_height' => $this->getOption('max_height')));
         } elseif ($width > $this->getOption('max_width')) {
             throw new sfValidatorError($this, 'max_width', array('width' => $width, 'max_width' => $this->getOption('max_width')));
         } elseif ($height > $this->getOption('max_height')) {
             throw new sfValidatorError($this, 'max_height', array('height' => $height, 'max_height' => $this->getOption('max_height')));
         }
     }
     // now tell sfValidatorFile to do its own checks
     return $file;
 }