示例#1
0
 /**
  * Generate a new manipulated file, such as a crop.
  * @param $name string directory
  * @param callable $callable  ($image)
  * @return \Exception|null|int
  */
 public function generate($name, callable $callable)
 {
     if (!$this->isImage()) {
         return null;
     }
     $path = Media::basePath($name);
     if (!file_exists($path)) {
         mkdir($path, 0755);
     }
     try {
         $img = Image::make($this->path());
         $callable($img);
     } catch (\Exception $error) {
         return $error;
     }
     return $img ? $img->save($path . $this->file_name) : null;
 }