1 <?php
2
3 class rex_effect_filter_blur extends rex_effect_abstract
4 {
5 protected $options;
6 protected $options_smoothit;
7
8 public function __construct()
9 {
10 $this->options = ['', 'gaussian', 'selective'];
11 $this->options_smoothit = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, '', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
12 }
13
14 public function execute()
15 {
16 $options = [];
17 $options['gaussian'] = IMG_FILTER_GAUSSIAN_BLUR;
18 $options['selective'] = IMG_FILTER_SELECTIVE_BLUR;
19
20 $this->media->asImage();
21 $gdimage = $this->media->getImage();
22
23 $this->params['repeats'] = (int) $this->params['repeats'];
24 if ($this->params['repeats'] < 0) {
25 return;
26 }
27
28 if (!in_array($this->params['type'], $this->options)) {
29 $this->params['type'] = '';
30 }
31
32 if (!in_array($this->params['smoothit'], $this->options_smoothit)) {
33 $this->params['smoothit'] = '';
34 }
35
36 for ($i = 0; $i < $this->params['repeats']; ++$i) {
37 if ($this->params['smoothit'] != '') {
38 imagefilter($gdimage, IMG_FILTER_SMOOTH, $this->params['smoothit']);
39 }
40
41 if ($this->params['type'] != '') {
42 imagefilter($gdimage, $options[$this->params['type']]);
43 }
44 }
45 }
46
47 public function getName()
48 {
49 return rex_i18n::msg('media_manager_effect_blur');
50 }
51
52 public function getParams()
53 {
54 return [
55 [
56 'label' => rex_i18n::msg('media_manager_effect_blur_repeats'),
57 'name' => 'repeats',
58 'type' => 'int',
59 'default' => '10',
60 ],
61 [
62 'label' => rex_i18n::msg('media_manager_effect_blur_type'),
63 'name' => 'type',
64 'type' => 'select',
65 'options' => $this->options,
66 'default' => 'gaussian',
67 ],
68 [
69 'label' => rex_i18n::msg('media_manager_effect_blur_smoothit'),
70 'name' => 'smoothit',
71 'type' => 'select',
72 'options' => $this->options_smoothit,
73 'default' => '',
74 ],
75 ];
76 }
77 }
78