Passed
Branch master (875b53)
by Sasaya
02:40
created

WatermarkPlugin::getWatermark()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0109

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 9
cp 0.7778
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.0109
1
<?php
2
3
namespace UniSharp\Uploadable\Plugins;
4
5
use Intervention\Image\Facades\Image;
6
use Illuminate\Support\Facades\Storage;
7
8
class WatermarkPlugin
9
{
10 2
    public function handle($path)
11
    {
12 2
        $image = Image::make($path);
13 2
        $image->insert($this->getWatermark($image), 'bottom-right');
14 2
        $image->save();
15 2
    }
16
17 2
    protected function getWatermark($image)
18
    {
19 2
        $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
20 2
        $watermarkPath = $storagePath . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'watermark.png';
21 2
        $watermark = Image::make($watermarkPath);
22
23 2
        $watermark->resize($image->getWidth() / 2.5, null, function ($constraint) {
24
            $constraint->aspectRatio();
25
            $constraint->upsize();
26 2
        });
27
28 2
        return $watermark;
29
    }
30
}
31