1 <?php
 2 
 3 /**
 4  * @package redaxo\media-manager
 5  */
 6 class rex_effect_image_properties extends rex_effect_abstract
 7 {
 8     public function execute()
 9     {
10         $media = $this->media;
11 
12         if (!empty($this->params['jpg_quality'])) {
13             $media->setImageProperty('jpg_quality', $this->params['jpg_quality']);
14         }
15 
16         if (!empty($this->params['png_compression'])) {
17             $media->setImageProperty('png_compression', $this->params['png_compression']);
18         }
19 
20         if (!empty($this->params['webp_quality'])) {
21             $media->setImageProperty('webp_quality', $this->params['webp_quality']);
22         }
23 
24         if ($this->params['interlace']) {
25             $interlace = explode('|', trim($this->params['interlace'], '|'));
26             $interlace = in_array('- off -', $interlace) ? [] : $interlace;
27             $media->setImageProperty('interlace', $interlace);
28         }
29     }
30 
31     public function getName()
32     {
33         return rex_i18n::msg('media_manager_effect_image_properties');
34     }
35 
36     public function getParams()
37     {
38         return [
39             [
40                 'label' => rex_i18n::msg('media_manager_jpg_quality'),
41                 'notice' => rex_i18n::msg('media_manager_effect_image_properties_jpg_quality_notice'),
42                 'name' => 'jpg_quality',
43                 'type' => 'int',
44             ],
45             [
46                 'label' => rex_i18n::msg('media_manager_png_compression'),
47                 'notice' => rex_i18n::msg('media_manager_effect_image_properties_png_compression_notice').' '.rex_i18n::msg('media_manager_png_compression_note'),
48                 'name' => 'png_compression',
49                 'type' => 'int',
50             ],
51             [
52                 'label' => rex_i18n::msg('media_manager_webp_quality'),
53                 'notice' => rex_i18n::msg('media_manager_effect_image_properties_webp_quality_notice'),
54                 'name' => 'webp_quality',
55                 'type' => 'int',
56             ],
57             [
58                 'label' => rex_i18n::msg('media_manager_interlace'),
59                 'notice' => rex_i18n::msg('media_manager_effect_image_properties_interlace_notice'),
60                 'name' => 'interlace',
61                 'type' => 'select',
62                 'options' => ['- off -', 'jpg', 'png', 'gif'],
63                 'attributes' => ['multiple' => true, 'class' => 'selectpicker form-control'],
64                 'suffix' => '
65 <script type="text/javascript">
66     $(function() {
67         var $field = $("#media-manager-rex-effect-image-properties-interlace-select");
68         
69         $field.on("changed.bs.select", function (event, clickedIndex, newValue, oldValue) {
70             var off = "- off -";
71             if (0 == clickedIndex && newValue) {
72                 $field.selectpicker("val", [off]);
73             }
74             if (0 != clickedIndex && newValue) {
75                 var value = $field.selectpicker("val");
76                 var index = value.indexOf(off);
77                 if (index > -1) {
78                     value.splice(index, 1);
79                     $field.selectpicker("val", value);
80                 }
81             }
82         });
83     });
84 </script>',
85             ],
86         ];
87     }
88 }
89