public function execute() { /** @var $dimensionSettings ImageDimension **/ $dimensionSettings = $this->cropping->getDimension(); // first delete old file $oldFile = sprintf('%s/%s.%s', $this->uploadPath, $this->oldFile->getFileName(), $this->attachment->getExtension()); if (file_exists($oldFile)) { @unlink($oldFile); } /* @var Box */ $size = $this->setBox($dimensionSettings); $originalFile = sprintf('%s/%s.%s', $this->uploadPath, $this->attachment->getName(), $this->attachment->getExtension()); $checkFilename = sprintf('%s/%s.%s', $this->uploadPath, $this->cropping->getFileName(), $this->attachment->getExtension()); if ($this->oldFile->getName() == $this->cropping->getName() && file_exists($checkFilename)) { $cropName = $this->cropping->getFileName(); } else { $fileDuplicateChecker = $this->checkDuplicateFile($this->cropping->getName(), $this->attachment->getExtension()); $cropName = $fileDuplicateChecker['name']; $counter = $fileDuplicateChecker['counter']; $this->cropping->setCounter($counter); } $cropFile = sprintf('%s/%s.%s', $this->uploadPath, $cropName, $this->attachment->getExtension()); $this->imagine->open($originalFile)->crop(new Point($this->x, $this->y), new Box($this->width, $this->height))->save($cropFile); $this->imagine->open($cropFile)->thumbnail($size, ImageInterface::THUMBNAIL_INSET)->save($cropFile); $this->cropping->setFileName($cropName); $this->cropping->setChecksum(sha1_file($cropFile)); $initSize = new MediaFile($cropFile); $this->cropping->setClientHeight($initSize->getHeight()); $this->cropping->setClientWidth($initSize->getWidth()); return $this->cropping; }