1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use FFMpeg\Format\Video\X264; |
7
|
|
|
use Mostafaznv\Larupload\DTOs\Style\StreamStyle; |
8
|
|
|
use Mostafaznv\Larupload\DTOs\Style\ImageStyle; |
9
|
|
|
use Mostafaznv\Larupload\DTOs\Style\VideoStyle; |
10
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadFileType; |
11
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle; |
12
|
|
|
use Mostafaznv\Larupload\Larupload; |
13
|
|
|
use Mostafaznv\Larupload\UploadEntities; |
14
|
|
|
|
15
|
|
|
trait UploadEntityStyle |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Styles for image files |
19
|
|
|
* |
20
|
|
|
* @var ImageStyle[] |
21
|
|
|
*/ |
22
|
|
|
protected array $imageStyles = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Styles for video files |
26
|
|
|
* |
27
|
|
|
* @var VideoStyle[] |
28
|
|
|
*/ |
29
|
|
|
protected array $videoStyles = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Stream styles |
33
|
|
|
* |
34
|
|
|
* @var StreamStyle[] |
35
|
|
|
*/ |
36
|
|
|
protected array $streams = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Cover style |
40
|
|
|
* |
41
|
|
|
* @var ImageStyle |
42
|
|
|
*/ |
43
|
|
|
protected ImageStyle $coverStyle; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function image(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
47
|
|
|
{ |
48
|
|
|
$this->imageStyles[$name] = ImageStyle::make($name, $width, $height, $mode); |
49
|
|
|
|
50
|
|
|
return $this; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function video(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, X264 $format = new X264, bool $padding = false): UploadEntities |
54
|
|
|
{ |
55
|
|
|
$this->videoStyles[$name] = VideoStyle::make($name, $width, $height, $mode, $format, $padding); |
56
|
|
|
|
57
|
|
|
return $this; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function stream(string $name, int $width, int $height, X264 $format, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, bool $padding = false): UploadEntities |
61
|
|
|
{ |
62
|
|
|
$this->streams[$name] = StreamStyle::make($name, $width, $height, $format, $mode, $padding); |
63
|
|
|
|
64
|
|
|
return $this; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function coverStyle(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
68
|
|
|
{ |
69
|
|
|
$this->coverStyle = ImageStyle::make($name, $width, $height, $mode); |
70
|
|
|
|
71
|
|
|
return $this; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function styleHasFile(string $style): bool |
75
|
|
|
{ |
76
|
|
|
if (in_array($style, [Larupload::ORIGINAL_FOLDER, Larupload::COVER_FOLDER])) { |
77
|
|
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$type = $this->output['type']; |
81
|
|
|
$types = [ |
82
|
|
|
LaruploadFileType::VIDEO->name, |
|
|
|
|
83
|
|
|
LaruploadFileType::IMAGE->name |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
if (in_array($type, $types)) { |
87
|
|
|
$styles = $type === LaruploadFileType::IMAGE->name |
88
|
|
|
? $this->imageStyles |
89
|
|
|
: $this->videoStyles; |
90
|
|
|
|
91
|
|
|
return array_key_exists($style, $styles); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|