-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatermark.module
executable file
·99 lines (89 loc) · 2.64 KB
/
watermark.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
<?php
/**
* Implements hook_image_effect_info().
*/
function watermark_image_effect_info() {
$effects = array();
$effects['watermark'] = array(
'label' => t('Watermark'),
'help' => t('Add a watermark to an image.'),
'effect callback' => 'watermark_effect',
'form callback' => 'watermark_form',
'summary theme' => 'watermark_summary',
);
return $effects;
}
/**
* Image effect callback; add a text watermark to an image.
*
* @param $image
* An image object returned by image_load().
* @param $data
* An array of attributes to use when performing the watermark effect.
* @return
* TRUE on success. FALSE on failure.
*/
function watermark_effect(&$image, $data) {
$data['text_color'] = str_replace('#', '', $data['text_color']);
$red = hexdec(substr($data['text_color'], 0, 2));
$green = hexdec(substr($data['text_color'], 2, 2));
$blue = hexdec(substr($data['text_color'], 4));
$color = imagecolorallocate($image->resource, $red, $green, $blue);
imagestring($image->resource, 5, 5, 5, $data['text'], $color);
}
/**
* Form structure for the watermark configuration form.
*
* @param $data
* The current configuration for this watermark effect.
*/
function watermark_form($data) {
$form['text_color'] = array(
'#type' => 'textfield',
'#default_value' => (isset($data['text_color'])) ? $data['text_color'] : '#FFFFFF',
'#title' => t('Text color'),
'#description' => t('The color of the text to be used for this watermark. Use web-style hex colors (#FFFFFF for white, #000000 for black).'),
'#size' => 7,
'#maxlength' => 7,
'#element_validate' => array('image_effect_color_validate'),
);
$form['text'] = array(
'#type' => 'textfield',
'#default_value' => (isset($data['text'])) ? $data['text'] : 'Drupal loves kittens!',
'#title' => t('Watermark text'),
'#description' => t('Text to be written on the image.'),
'#size' => 30,
'#maxlength' => 60,
);
return $form;
}
/**
* Theme callback for image watermark effect summary output.
*
* @param $variables
* An associative array containing configuration data.
*/
function theme_watermark_summary($variables) {
$data = $variables['data'];
print_r($data);
return t('with color @textcolor', array('@textcolor' => $data['text_color']));
}
/**
* Implements hook_image_default_styles().
*/
function watermark_image_default_styles() {
$styles = array();
$styles['yar'] = array(
'effects' => array(
array(
'name' => 'watermark',
'data' => array(
'text_color' => '#000000',
'text' => 'YAR!'
),
'weight' => 0,
),
),
);
return $styles;
}