/**
  * @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;
 }