/
effect_abstract.php
96 lines (87 loc) · 2.55 KB
/
effect_abstract.php
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
<?php
/**
* @package redaxo\media-manager
*/
abstract class rex_effect_abstract
{
/** @var rex_managed_media */
public $media;
/**
* effekt parameter.
*
* @var array<string, mixed>
*/
public $params = [];
public function __construct()
{
}
/**
* @return void
*/
public function setMedia(rex_managed_media $media)
{
$this->media = $media;
}
/**
* @param array<string, mixed> $params
* @return void
*/
public function setParams(array $params)
{
$this->params = $params;
}
/**
* @return void
*/
abstract public function execute();
/**
* @return string
*/
public function getName()
{
return static::class;
}
/**
* Returns a array of array items each describing a spec of a input field with which the enduser can configure parameters for this effect.
*
* Example:
* return [
* [
* 'label' => rex_i18n::msg('...'), -> a short user-friendly field label
* 'notice' => rex_i18n::msg('...'), -> additional description.
* 'name' => 'contrast', -> name of your parameter. this will be the index within $this->params
* 'type' => 'int', -> scalar storage type
* 'default' => '', -> default value
* ],
* // ... the next input-field spec
* ];
*
* @return list<array{label: string, name: string, type: 'int'|'float'|'string'|'select'|'media', default?: mixed, notice?: string, prefix?: string, suffix?: string, attributes?: array, options?: array}>
*/
public function getParams()
{
// implement me in your subclass.
return [];
}
/**
* @param resource $gdImage
* @return void
*/
protected function keepTransparent($gdImage)
{
$image = $this->media;
if ('png' == $image->getFormat() || 'webp' == $image->getFormat()) {
imagealphablending($gdImage, false);
imagesavealpha($gdImage, true);
} elseif ('gif' == $image->getFormat()) {
$gdimage = $image->getImage();
$colorTransparent = imagecolortransparent($gdimage);
imagepalettecopy($gdimage, $gdImage);
if ($colorTransparent > 0) {
imagefill($gdImage, 0, 0, $colorTransparent);
imagecolortransparent($gdImage, $colorTransparent);
}
imagetruecolortopalette($gdImage, true, 256);
}
}
}