Conditions | 6 |
Paths | 7 |
Total Lines | 25 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
18 | protected function processImage(ImageManager $imageManager, $model) |
||
19 | { |
||
20 | if (! in_array(StorageTrait::class, class_uses($model))) { |
||
21 | throw new InvalidArgumentException('The model you used does not use the Storage trait'); |
||
|
|||
22 | } |
||
23 | |||
24 | if ($model->images()->exists()) { |
||
25 | foreach ($model->images as $image) { |
||
26 | $originalFile = $this->getImage($model->filesDir(), $image->name); |
||
27 | |||
28 | $thumbNailsDimensions = collect($model->getImageDimensions()) |
||
29 | ->except(0) |
||
30 | ->toArray(); |
||
31 | |||
32 | foreach ($thumbNailsDimensions as $thumbNailsDimension) { |
||
33 | |||
34 | try { |
||
35 | $thumbNail = $this->getImage($model->filesDir(), $image->name, $thumbNailsDimension); |
||
36 | $imageManager->make($originalFile)->fit($thumbNailsDimension, $thumbNailsDimension, |
||
37 | function ($constraint) { |
||
38 | $constraint->upsize(); |
||
39 | $constraint->aspectRatio(); |
||
40 | }, 'center')->save($thumbNail); |
||
41 | } catch (\Exception $e) { |
||
42 | Log::error($e->getMessage()); |
||
43 | } |
||
49 |