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