Esempio n. 1
0
 /**
  * @return NotBlank
  */
 public function validate()
 {
     $height = array();
     $width = array();
     foreach ($this->dimensionContainer->getDimensions() as $dimension) {
         if ($dimension->getFixedHeight() > 0) {
             $height[] = $dimension->getFixedHeight();
         }
         if ($dimension->getMinHeight() > 0) {
             $height[] = $dimension->getMinHeight();
         }
         if ($dimension->getFixedWidth() > 0) {
             $width[] = $dimension->getFixedWidth();
         }
         if ($dimension->getMinWidth() > 0) {
             $width[] = $dimension->getMinWidth();
         }
     }
     if ($this->attachment->getWidth() > 0 && count($height) > 0) {
         if (max($height) > $this->attachment->getHeight() || max($width) > $this->attachment->getWidth()) {
             return new TranslatorObject('bigfish.media.error.minsize', array('%min_width%' => max($width), '%min_height%' => max($height), '%currentWidth%' => $this->attachment->getWidth(), '%currentHeight%' => $this->attachment->getHeight()));
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @param Attachment    $attachment
  * @param ImageCropping $cropping
  *
  * @return $this
  */
 public function initialize(Attachment $attachment, ImageCropping $cropping, ImageCropping $old = null)
 {
     $x = (int) ceil($cropping->getX());
     $y = (int) ceil($cropping->getY());
     $width = (int) ceil($cropping->getWidth());
     $height = (int) ceil($cropping->getHeight());
     $checkWidth = $width + $x - $attachment->getWidth();
     $checkHeight = $height + $y - $attachment->getHeight();
     if ($checkWidth > 0) {
         $x = (int) $x - $checkWidth;
     }
     if ($checkHeight > 0) {
         $y = (int) $y - $checkHeight;
     }
     if ($width > $attachment->getWidth()) {
         $width = $attachment->getWidth();
     }
     if ($height > $attachment->getHeight()) {
         $height = $attachment->getHeight();
     }
     if ($y < 0) {
         $y = 0;
     }
     if ($x < 0) {
         $x = 0;
     }
     $this->x = $x;
     $this->y = $y;
     $this->width = $width;
     $this->height = $height;
     $this->attachment = $attachment;
     $this->cropping = $cropping;
     $this->oldFile = $old;
     return $this;
 }