This repository was archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhelpers.php
More file actions
37 lines (30 loc) · 1.26 KB
/
helpers.php
File metadata and controls
37 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
if (! function_exists('move_file')) {
function move_file($file, $type='products.slide', $withWatermark = false)
{
// Grab all variables
$path = explode('.', $type)[0];
$destinationPath = config('variables.'.$path.'.folder');
$width = config('variables.' . $type . '.width');
$height = config('variables.' . $type . '.height');
$full_name = str_random(16) . '.' . $file->getClientOriginalExtension();
if ($width == null && $height == null) { // Just move the file
$file->storeAs($destinationPath, $full_name);
return $full_name;
}
// Create the Image
$image = Image::make($file->getRealPath());
if ($width == null || $height == null) {
$image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
}else{
$image->fit($width, $height);
}
if ($withWatermark) {
$watermark = Image::make(public_path() . '/img/watermark.png')->resize($width * 0.5, null);
$image->insert($watermark, 'center');
}
return $image->save($destinationPath . '/' . $full_name)->basename;
}
}