-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiek.module
367 lines (336 loc) · 10.3 KB
/
iek.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
/**
* @file
* Contains "iek" module.
*/
/**
* Implements hook_theme().
*/
function iek_theme() {
return [
'iek_image_border_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_corner_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_padding_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_resize_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_watermark_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_overlay_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
'iek_image_filter_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
];
}
/**
* Implements hook_iek_watermark_font().
*/
function iek_iek_watermark_font() {
$path = drupal_get_path('module', 'iek') . '/fonts';
return [
'bubble' => [
'name' => 'bubble',
'title' => t('Bubble'),
'file' => 'bubble.ttf',
'path' => $path,
],
'digital' => [
'name' => 'digital',
'title' => t('Digital'),
'file' => 'digital.ttf',
'path' => $path,
],
'snow' => [
'name' => 'snow',
'title' => t('Snow'),
'file' => 'snow.ttf',
'path' => $path,
],
'tuffy_bold' => [
'name' => 'tuffy_bold',
'title' => t('Tuffy Bold'),
'file' => 'tuffy_bold.ttf',
'path' => $path,
],
'wedding' => [
'name' => 'wedding',
'title' => t('Wedding'),
'file' => 'wedding.ttf',
'path' => $path,
],
];
}
/**
* Implements hook_iek_overlay().
*/
function iek_iek_overlay() {
$path = drupal_get_path('module', 'iek') . '/overlays';
return [
'basic' => [
'name' => 'basic',
'title' => t('Basic'),
'children' => [
'basic_dropshadow_001_1024x768' => [
'name' => 'basic_dropshadow_001_1024x768',
'title' => t('Drop shadow 001 - 1024x768'),
'path' => $path . '/basic',
'file' => 'basic-dropshadow-001-1024x768.png',
],
'basic_dropshadow_001_768x1024' => [
'name' => 'basic_dropshadow_001_768x1024',
'title' => t('Drop shadow 001 - 768x1024'),
'path' => $path . '/basic',
'file' => 'basic-dropshadow-001-768x1024.png',
],
'basic_dropshadow_001_600x600' => [
'name' => 'basic_dropshadow_001_600x600',
'title' => t('Drop shadow 001 - 600x600'),
'path' => $path . '/basic',
'file' => 'basic-dropshadow-001-600x600.png',
],
'basic_film_001_1024x768' => [
'name' => 'basic_film_001_1024x768',
'title' => t('Film 001 - 1024x768'),
'path' => $path . '/basic',
'file' => 'basic-film-001-1024x768.png',
],
'basic_film_001_768x1024' => [
'name' => 'basic_film_001_768x1024',
'title' => t('Film 001 - 768x1024'),
'path' => $path . '/basic',
'file' => 'basic-film-001-768x1024.png',
],
'basic_film_001_600x600' => [
'name' => 'basic_film_001_600x600',
'title' => t('Film 001 - 600x600'),
'path' => $path . '/basic',
'file' => 'basic-film-001-600x600.png',
],
'basic_overlap_001_1024x768' => [
'name' => 'basic_overlap_001_1024x768',
'title' => t('Overlap 001 - 1024x768'),
'path' => $path . '/basic',
'file' => 'basic-overlap-001-1024x768.png',
],
'basic_overlap_001_768x1024' => [
'name' => 'basic_overlap_001_768x1024',
'title' => t('Overlap 001 - 768x1024'),
'path' => $path . '/basic',
'file' => 'basic-overlap-001-768x1024.png',
],
'basic_overlap_001_600x600' => [
'name' => 'basic_overlap_001_600x600',
'title' => t('Overlap 001 - 600x600'),
'path' => $path . '/basic',
'file' => 'basic-overlap-001-600x600.png',
],
'basic_stamp_001_1024x768' => [
'name' => 'basic_stamp_001_1024x768',
'title' => t('Stamp 001 - 1024x768'),
'path' => $path . '/basic',
'file' => 'basic-stamp-001-1024x768.png',
],
'basic_stamp_001_768x1024' => [
'name' => 'basic_stamp_001_768x1024',
'title' => t('Stamp 001 - 768x1024'),
'path' => $path . '/basic',
'file' => 'basic-stamp-001-768x1024.png',
],
'basic_stamp_001_600x600' => [
'name' => 'basic_stamp_001_600x600',
'title' => t('Stamp 001 - 600x600'),
'path' => $path . '/basic',
'file' => 'basic-stamp-001-600x600.png',
],
],
],
];
}
/**
* Converts color format from Hex to RGB.
*
* @param string $hex_str
* A Hex color format like '#cccccc'.
* @param bool $return_as_string
* A boolean flag to indicate to return a string or an array.
* @param string $separator
* A character or string to join the RGB array elements.
*
* @return array|string|bool
* - An associative RGB array if 'return_as_string' is set to FALSE.
* - A RGB string that was split by the 'separator' will be returned if
* 'return_as_string' is set to TRUE.
* - Return FALSE if an invalid Hex color code.
*/
function iek_hex2rgb($hex_str, $return_as_string = FALSE, $separator = ',') {
// Gets a proper Hex string.
$hex_str = preg_replace("/[^0-9A-Fa-f]/", '', $hex_str);
$rgb_array = [];
// If a proper Hex code, convert using bitwise operation.
if (strlen($hex_str) == 6) {
$border_color_val = hexdec($hex_str);
$rgb_array['red'] = 0xFF & ($border_color_val >> 0x10);
$rgb_array['green'] = 0xFF & ($border_color_val >> 0x8);
$rgb_array['blue'] = 0xFF & $border_color_val;
}
// If shorthand notation, need some string manipulations.
elseif (strlen($hex_str) == 3) {
$rgb_array['red'] = hexdec(str_repeat(substr($hex_str, 0, 1), 2));
$rgb_array['green'] = hexdec(str_repeat(substr($hex_str, 1, 1), 2));
$rgb_array['blue'] = hexdec(str_repeat(substr($hex_str, 2, 1), 2));
}
else {
// Invalid Hex color code.
return FALSE;
}
// Returns the RGB string or the associative array.
return $return_as_string ? implode($separator, $rgb_array) : $rgb_array;
}
/**
* Gets a list of available watermark fonts.
*
* @param string $font_name
* A font name if you just want to get a particular watermark font.
* Leaves empty if you want to get all available watermark fonts.
*
* @return array
* Particular watermark font if the 'font_name' is given.
* All available watermark fonts otherwise.
*/
function iek_get_watermark_fonts($font_name = '') {
$fonts = \Drupal::moduleHandler()->invokeAll('iek_watermark_font');
// Invoke hook_iek_watermark_fonts_alter().
// To allow all modules to alter the fonts.
\Drupal::moduleHandler()->alter('iek_watermark_font', $fonts);
if (!empty($font_name)) {
if (isset($fonts[$font_name])) {
return $fonts[$font_name];
}
else {
return [];
}
}
return $fonts;
}
/**
* Gets a list of available image overlays.
*
* @param string $overlay_name
* A overlay name if you just want to get a particular image overlay.
* Leaves empty if you want to get all available overlays.
*
* @return array
* Particular overlays if the 'overlay_name' is given.
* All available overlays otherwise.
*/
function iek_get_overlays($overlay_name = '') {
$overlays = \Drupal::moduleHandler()->invokeAll('iek_overlay');
// Invoke hook_iek_overlay_alter().
// To allow all modules to alter the overlays.
\Drupal::moduleHandler()->alter('iek_overlay', $overlays);
if (!empty($overlay_name)) {
foreach ($overlays as $item1) {
foreach ($item1['children'] as $item2) {
if ($item2['name'] == $overlay_name) {
return $item2;
}
}
}
}
return $overlays;
}
/**
* Gets a list of available image filters.
*
* @return array
* All available filters array.
*/
function iek_get_image_filters() {
$filters = [
IMG_FILTER_NEGATE => t('Negate'),
IMG_FILTER_GRAYSCALE => t('Grayscale'),
IMG_FILTER_BRIGHTNESS => t('Brightness'),
IMG_FILTER_CONTRAST => t('Contrast'),
IMG_FILTER_COLORIZE => t('Colorize'),
IMG_FILTER_EDGEDETECT => t('Edgedetect'),
IMG_FILTER_EMBOSS => t('Emboss'),
IMG_FILTER_GAUSSIAN_BLUR => t('Gaussian blur'),
IMG_FILTER_SELECTIVE_BLUR => t('Selective blur'),
IMG_FILTER_MEAN_REMOVAL => t('Mean removal'),
IMG_FILTER_SMOOTH => t('Smooth'),
// IMG_FILTER_PIXELATE => t('Pixelate'),
];
return $filters;
}
/**
* Creates an image from file or URL.
*
* @param string $file
* Path to the image.
*
* @return resource|NULL
* An image identifier representing the image obtained from the given
* filename.
*/
function iek_gd_create_image($file) {
$data = @getimagesize($file);
switch ($data['mime']) {
case 'image/jpeg':
$image = imagecreatefromjpeg($file);
break;
case 'image/gif':
$image = imagecreatefromgif($file);
break;
case 'image/png':
$image = imagecreatefrompng($file);
break;
default:
$image = NULL;
break;
}
return $image;
}
/**
* Gets details about an image.
*
* Drupal supports GIF, JPG and PNG file formats when used with the GD
* toolkit, and may support others, depending on which toolkits are
* installed.
*
* @param string $filepath
* String specifying the path of the image file.
*
* @return array|bool
* FALSE, if the file could not be found or is not an image. Otherwise, a
* keyed array containing information about the image:
* - "width": Width, in pixels.
* - "height": Height, in pixels.
* - "mime_type": MIME type ('image/jpeg', 'image/gif', 'image/png').
* - "file_size": File size in bytes.
*/
function iek_image_get_info($filepath) {
$details = FALSE;
if (!is_file($filepath) && !is_uploaded_file($filepath)) {
return $details;
}
$image = Drupal::service('image.factory')->get($filepath);
if ($image) {
$details = [];
$details['width'] = $image->getToolkit()->getWidth();
$details['height'] = $image->getToolkit()->getHeight();
$details['mime_type'] = $image->getToolkit()->getMimeType();
}
if (isset($details) && is_array($details)) {
$details['file_size'] = filesize($filepath);
}
return $details;
}