Completed
Pull Request — master (#17)
by
unknown
02:05
created

ImageController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
ccs 0
cts 5
cp 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Intervention\Image\Facades\Image as Image;
7
8
class ImageController extends Controller
9
{
10
    /**
11
     * Create a new controller instance.
12
     *
13
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
    }
19
20
    /**
21
     * Show an image stored in private storage
22
     *
23
     * @param int $device_id
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function show($device_id)
27
    {
28
        $storagePath = storage_path('app/images/devices/');
29
        $imagePath = glob($storagePath . $device_id . "*" . ".jpg");
30
        
31
        if (!empty($imagePath))
32
            $image = Image::make($imagePath[0]);
33
        else
34
        {
35
            $imagePath = public_path() . '/img/video_not_found.jpg';
36
            $image = Image::make($imagePath);
37
        }
38
        
39
        return $image->response();
40
    }
41
    
42
    /**
43
     * Save an image's binary as a jpg to private storage
44
     *
45
     * @param int $device_id
46
     * @param string $binaryData
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function store($device_id, $binaryData)
50
    {
51
        $storagePath = storage_path('app/images/devices/') . $device_id . '.jpg';
52
        $image = Image::make($binaryData);
53
        $image->save($storagePath, 75);
54
    }
55
}
56