| Conditions | 2 |
| Paths | 2 |
| Total Lines | 25 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | public function getCropImage($overWrite = true) |
||
| 29 | { |
||
| 30 | $image_name = request('img'); |
||
| 31 | $image_path = $this->lfm->setName($image_name)->path('absolute'); |
||
| 32 | $crop_path = $image_path; |
||
| 33 | |||
| 34 | if (! $overWrite) { |
||
| 35 | $fileParts = explode('.', $image_name); |
||
| 36 | $fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time(); |
||
| 37 | $crop_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute'); |
||
| 38 | } |
||
| 39 | |||
| 40 | event(new ImageIsCropping($image_path)); |
||
| 41 | |||
| 42 | $crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY'); |
||
| 43 | |||
| 44 | // crop image |
||
| 45 | Image::make($image_path) |
||
| 46 | ->crop(...array_values($crop_info)) |
||
| 47 | ->save($crop_path); |
||
| 48 | |||
| 49 | // make new thumbnail |
||
| 50 | $this->lfm->generateThumbnail($image_name); |
||
| 51 | |||
| 52 | event(new ImageWasCropped($image_path)); |
||
| 53 | } |
||
| 60 |