This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_effects.module
160 lines (150 loc) · 5.24 KB
/
image_effects.module
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* @file
* Provides effects and operations for the Image API.
*/
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\image\ConfigurableImageEffectBase;
use Drupal\image_effects\Component\ColorUtility;
/**
* Implements hook_theme().
*/
function image_effects_theme() {
return [
// Render a color information box and string.
'image_effects_color_detail' => [
'variables' => [
'color' => '#000000',
'border' => FALSE,
'border_color' => '#000000',
],
],
// Background image effect - summary.
'image_effects_background_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Brightness image effect - summary.
'image_effects_brightness_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Color shift image effect - summary.
'image_effects_color_shift_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Contrast image effect - summary.
'image_effects_contrast_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Gaussian blur effect - summary.
'image_effects_gaussian_blur_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// ImageMagick arguments effect - summary.
'image_effects_imagemagick_arguments_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Mask image effect - summary.
'image_effects_mask_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Mirror image effect - summary.
'image_effects_mirror_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Opacity image effect - summary.
'image_effects_opacity_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Resize percentage image effect - summary.
'image_effects_resize_percentage_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Set canvas image effect - summary.
'image_effects_set_canvas_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Set transparent color image effect - summary.
'image_effects_set_transparent_color_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Render a preview of the Text Overlay in the image effect UI.
'image_effects_text_overlay_preview' => [
'variables' => ['success' => FALSE, 'preview' => []],
],
// Text overlay image effect - summary.
'image_effects_text_overlay_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Watemark image effect - summary.
'image_effects_watermark_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Convolution image effect - summary.
'image_effects_convolution_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Convolution sharpen image effect - summary.
'image_effects_convolution_sharpen_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
// Interlace image effect - summary.
'image_effects_interlace_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
];
}
/**
* Implements hook_image_effects_text_overlay_text_alter().
*/
function image_effects_image_effects_text_overlay_text_alter(&$text, ConfigurableImageEffectBase $image_effect) {
// Skip if the effect is not TextOverlayImageEffect or an alternative
// implementation.
if ($image_effect->getPluginId() !== "image_effects_text_overlay") {
return;
}
// Get effect data.
$effect_data = $image_effect->getConfiguration()['data'];
// Strip HTML tags, if requested.
if ($effect_data['text']['strip_tags'] === TRUE) {
$text = strip_tags($text);
}
// Decode HTML entities, if requested.
if ($effect_data['text']['decode_entities'] === TRUE) {
$text = Html::decodeEntities($text);
}
// Convert case, if requested.
if ($effect_data['text']['case_format']) {
$method_map = [
'upper' => 'strtoupper',
'lower' => 'strtolower',
'ucwords' => 'ucwords',
'ucfirst' => 'ucfirst',
];
$text = Unicode::{$method_map[$effect_data['text']['case_format']]}($text);
}
// Limit the maximum number of characters.
if ($effect_data['text']['maximum_chars'] > 0 && Unicode::strlen($text) > $effect_data['text']['maximum_chars']) {
$text = Unicode::substr($text, 0, $effect_data['text']['maximum_chars']) . $effect_data['text']['excess_chars_text'];
}
}
/**
* Prepares variables to get a color info.
*
* Default template: image-effects-color-detail.html.twig.
*/
function image_effects_preprocess_image_effects_color_detail(&$variables) {
$variables['#attached']['library'][] = 'image_effects/image_effects.admin.ui';
if ($variables['color']) {
if ($variables['border']) {
if ($variables['border_color'] == 'matchLuma') {
$variables['border_color'] = ColorUtility::matchLuma($variables['color']);
}
else {
$variables['border_color'] = Unicode::substr($variables['border_color'], 0, 7);
}
}
$variables['color_opacity'] = ColorUtility::rgbaToOpacity($variables['color']);
$variables['color'] = Unicode::substr($variables['color'], 0, 7);
}
}