Beispiel #1
0
 /**
  * @param $name
  * @param CropDimensions $dimensions
  * @return File
  */
 public function cropTempImage($name, CropDimensions $dimensions)
 {
     $config = $dimensions->getConfig();
     $path = $this->getTempFilePath($config, $name);
     $oldExtension = pathinfo($path, PATHINFO_EXTENSION);
     $img = ImageManagerStatic::make($path);
     $img->crop($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getX1(), $dimensions->getY1());
     $unique = uniqid();
     // Just if two people would edit the same image. Rather unlikely, but just in case
     $name = '_crop_' . $unique . '_' . $name;
     $tempPath = $this->getTempFilePath($config, $name);
     $img->save($tempPath);
     $img->destroy();
     $file = new File($tempPath);
     $md5 = md5_file($tempPath);
     $newName = $md5 . '.' . $oldExtension;
     $file = $file->move($this->getTempDir($config), $newName);
     return $file;
 }