-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathTransformationSample.php
More file actions
110 lines (100 loc) · 2.67 KB
/
Copy pathTransformationSample.php
File metadata and controls
110 lines (100 loc) · 2.67 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* This file is part of the Cloudinary PHP package.
*
* (c) Cloudinary
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cloudinary\Samples;
use Cloudinary\Asset\Image;
use Cloudinary\Asset\Video;
use Cloudinary\StringUtils;
use Cloudinary\Tag\ImageTag;
use Cloudinary\Tag\VideoTag;
use Cloudinary\Transformation\Transformation;
require_once __DIR__ . '/Sample.php';
require_once __DIR__ . '/Tabs/CodeTab.php';
require_once __DIR__ . '/Tabs/TransformationTab.php';
/**
* Class TransformationSample
*/
class TransformationSample extends Sample
{
/**
* @var Transformation
*/
private $transformation;
/**
* @var string
*/
private $publicId;
/**
* @var string
*/
private $type;
/**
* TransformationSample constructor.
* @param string $name
* @param $transformation
* @param $code
* @param $publicId
* @param string $type
*/
public function __construct($transformation, $code, $publicId = 'sample', $name = 'sample', $type = 'image')
{
parent::__construct($name, $code);
$this->transformation = $transformation;
$this->publicId = $publicId;
$this->type = $type;
}
/**
* @return array
*/
protected function createTabs()
{
return [
$this->createCodeTab(),
new TransformationTab(
$this->transformation,
$this->code,
$this->publicId
)
];
}
/**
* @return string
*/
protected function getExample()
{
$publicId = $this->publicId;
$transformation = $this->transformation;
if (StringUtils::endsWith($publicId, '.mp4')) {
return $this->createVideoTag(Video::upload($publicId), $transformation);
}
return $this->createImageTag(Image::upload($publicId), $transformation);
}
/**
* @param Image $image
* @param $transformation
* @return string
*/
private function createImageTag($image, $transformation)
{
$url = $image->toUrl($transformation);
$tag = (new ImageTag($image, null, $transformation));
return $this->getExampleHtml($url, $tag);
}
/**
* @param Video $video
* @param $transformation
* @return string
*/
private function createVideoTag($video, $transformation)
{
$url = $video->toUrl($transformation);
$tag = (new VideoTag($video->setTransformation($transformation)))->setAttribute('controls');
return $this->getExampleHtml($url, $tag);
}
}