attachment_id = $data['attachment_id']; $this->attachment = Attachment::find($this->attachment_id); if (!$this->shouldResize()) { return; } $this->crop = $data['crop']; $this->sizes = Setting::get('srcx'); Storage::disk($this->disk)->makeDirectory('cropped'); $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); Storage::disk($this->disk)->makeDirectory($this->attachment->path); if ($width > $this->maxFilesize) { $r = Resizer::open($this->fullPath); $r->resize($this->maxFilesize, 0); $r->save($this->fullPath); } $r = Resizer::open($this->fullPath); $r->save(Storage::disk($this->disk)->path($this->attachment->getVersionPath('full'))); [ $width, $height ] = getimagesize($this->fullPath); foreach ($this->sizes as $w) { if ($width < $w) { continue; } $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); } private function shouldResize() { return $this->attachment->source->isCroppable(); } }