ProcessImage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 14 1
1
<?php
2
3
namespace FaithGen\SDK\Listeners\Ministry\Profile\ImageSaved;
4
5
use FaithGen\SDK\Events\Ministry\Profile\ImageSaved;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Intervention\Image\ImageManager;
8
9
class ProcessImage implements ShouldQueue
10
{
11
    /**
12
     * @var ImageManager
13
     */
14
    private $imageManager;
15
16
    /**
17
     * Create the event listener.
18
     *
19
     * @param ImageManager $imageManager
20
     */
21
    public function __construct(ImageManager $imageManager)
22
    {
23
        $this->imageManager = $imageManager;
24
    }
25
26
    /**
27
     * Handle the event.
28
     *
29
     * @param ImageSaved $event
30
     * @return void
31
     */
32
    public function handle(ImageSaved $event)
33
    {
34
        $ogImage = storage_path('app/public/profile/original/').$event->getImage()->name;
35
        $thumb100 = storage_path('app/public/profile/100-100/').$event->getImage()->name;
36
        $thumb50 = storage_path('app/public/profile/50-50/').$event->getImage()->name;
37
38
        $this->imageManager->make($ogImage)->fit(100, 100, function ($constraint) {
39
            $constraint->upsize();
40
            $constraint->aspectRatio();
41
        }, 'center')->save($thumb100);
42
        $this->imageManager->make($ogImage)->fit(50, 50, function ($constraint) {
43
            $constraint->upsize();
44
            $constraint->aspectRatio();
45
        }, 'center')->save($thumb50);
46
    }
47
}
48