attachment_id = $data['attachment_id']; $this->crop = $data['crop']; $this->sizes = Setting::get('srcx'); Storage::disk($this->disk)->makeDirectory('cropped'); $this->attachment = Attachment::find($this->attachment_id); $this->fullPath = Storage::disk($this->disk)->path($this->attachment->source->path); $this->crop(); $this->createVersions(); } public function crop() { if ($this->crop === null) { return; } $r = Resizer::open($this->fullPath); $r->crop(floor($this->crop['x']), floor($this->crop['y']), floor($this->crop['w']), floor($this->crop['h'])); $r->save($this->fullPath); } public function createVersions() { [ $width, $height ] = getimagesize($this->fullPath); if ($width > $this->maxFilesize) { $r = Resizer::open($this->fullPath); $r->resize($this->maxFilesize, 0); $r->save($this->fullPath); } [ $width, $height ] = getimagesize($this->fullPath); Storage::disk($this->disk)->makeDirectory($this->attachment->path); foreach ($this->sizes as $w) { if ($width < $w) { continue; } Storage::disk($this->disk)->makeDirectory($this->attachment->path); $r = Resizer::open($this->fullPath); $r->resize($w, 0); $r->save(Storage::disk($this->disk)->path($this->attachment->getVersionPath($w))); } } private function getStrategy() { return app($this->strategy); } }