| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* default transformer transforms
|
| 4 |
*/
|
| 5 |
|
| 6 |
/**
|
| 7 |
* return an array of transforms implemented by this module.
|
| 8 |
*
|
| 9 |
* 'basename' => array( 'title'=>'', 'mimes'=>'', 'extensions'=>array(), 'queue'=>BOOL );
|
| 10 |
* basename is the basename from which functions _form and _perform will be generated.
|
| 11 |
* title is a human readable title
|
| 12 |
* mimes is an array of valid mime types this transform can operate on.
|
| 13 |
* extensions is an array of valid extensions this transform can operate on.
|
| 14 |
*/
|
| 15 |
function transformer_transforms_transformer() {
|
| 16 |
return array(
|
| 17 |
'transformer_transforms_crop' => array(
|
| 18 |
'title' => t('Crop'),
|
| 19 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 20 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 21 |
'queue' => FALSE,
|
| 22 |
),
|
| 23 |
'transformer_transforms_scale' => array(
|
| 24 |
'title' => t('Scale'),
|
| 25 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 26 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 27 |
'queue' => FALSE,
|
| 28 |
),
|
| 29 |
'transformer_transforms_resize' => array(
|
| 30 |
'title' => t('Resize'),
|
| 31 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 32 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 33 |
'queue' => FALSE,
|
| 34 |
),
|
| 35 |
'transformer_transforms_fill' => array(
|
| 36 |
'title' => t('Fill'),
|
| 37 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 38 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 39 |
'queue' => FALSE,
|
| 40 |
),
|
| 41 |
'transformer_transforms_rotate' => array(
|
| 42 |
'title' => t('Rotate'),
|
| 43 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 44 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 45 |
'queue' => FALSE,
|
| 46 |
),
|
| 47 |
);
|
| 48 |
}
|
| 49 |
|
| 50 |
function transformer_transforms_crop_form($data) {
|
| 51 |
//debug_msg($transform);
|
| 52 |
$form = array();
|
| 53 |
$form['width'] = array(
|
| 54 |
'#type' => 'textfield',
|
| 55 |
'#size' => 15,'#maxlength' => 30,
|
| 56 |
'#title' => t('Width'),
|
| 57 |
'#default_value' => $data['width'],
|
| 58 |
);
|
| 59 |
$form['height'] = array(
|
| 60 |
'#type' => 'textfield',
|
| 61 |
'#title' => t('Height'),
|
| 62 |
'#size' => 15,'#maxlength' => 30,
|
| 63 |
'#default_value' => $data['height'],
|
| 64 |
);
|
| 65 |
$form['xoffset'] = array(
|
| 66 |
'#type' => 'textfield',
|
| 67 |
'#title' => t('X Offset'),
|
| 68 |
'#size' => 15,'#maxlength' => 30,
|
| 69 |
'#default_value' => $data['xoffset'],
|
| 70 |
);
|
| 71 |
$form['yoffset'] = array(
|
| 72 |
'#type' => 'textfield',
|
| 73 |
'#title' => t('Y Offset'),
|
| 74 |
'#size' => 15,'#maxlength' => 30,
|
| 75 |
'#default_value' => $data['yoffset'],
|
| 76 |
);
|
| 77 |
$form['#validate'] = array('transformer_crop_form_validate' => array());
|
| 78 |
return $form;
|
| 79 |
}
|
| 80 |
|
| 81 |
function transformer_transforms_crop_form_validate() {
|
| 82 |
}
|
| 83 |
|
| 84 |
function transformer_transforms_crop_perform($source, $destination, $data) {
|
| 85 |
return image_crop($source, $destination, $data['xoffset'] , $data['yoffset'], $data['width'], $data['height']);
|
| 86 |
}
|
| 87 |
|
| 88 |
function transformer_transforms_scale_form($data) {
|
| 89 |
$form = array();
|
| 90 |
$form['width'] = array(
|
| 91 |
'#type' => 'textfield',
|
| 92 |
'#size' => 15,'#maxlength' => 30,
|
| 93 |
'#title' => t('Width'),
|
| 94 |
'#default_value' => $data['width'],
|
| 95 |
);
|
| 96 |
$form['height'] = array(
|
| 97 |
'#type' => 'textfield',
|
| 98 |
'#size' => 15,'#maxlength' => 30,
|
| 99 |
'#title' => t('Height'),
|
| 100 |
'#default_value' => $data['height'],
|
| 101 |
);
|
| 102 |
$form['#validate'] = array('transformer_transforms_scale_form_validate' => array());
|
| 103 |
return $form;
|
| 104 |
}
|
| 105 |
|
| 106 |
function transformer_transforms_scale_form_validate() {
|
| 107 |
}
|
| 108 |
|
| 109 |
function transformer_transforms_scale_perform($source, $destination, $data) {
|
| 110 |
//drupal_set_message('scale: '. $source .', '. $destination .', '. $data['width'] .', '. $data['height']);
|
| 111 |
return image_scale($source, $destination, $data['width'], $data['height']);
|
| 112 |
}
|
| 113 |
|
| 114 |
function transformer_transforms_resize_form($data) {
|
| 115 |
$form = array();
|
| 116 |
$form['width'] = array(
|
| 117 |
'#type' => 'textfield',
|
| 118 |
'#size' => 15,'#maxlength' => 30,
|
| 119 |
'#title' => t('Width'),
|
| 120 |
'#default_value' => $data['width'],
|
| 121 |
);
|
| 122 |
$form['height'] = array(
|
| 123 |
'#type' => 'textfield',
|
| 124 |
'#size' => 15,'#maxlength' => 30,
|
| 125 |
'#title' => t('Height'),
|
| 126 |
'#default_value' => $data['height'],
|
| 127 |
);
|
| 128 |
$form['#validate'] = array('transformer_transforms_resize_form_validate' => array());
|
| 129 |
return $form;
|
| 130 |
}
|
| 131 |
|
| 132 |
function transformer_transforms_resize_form_validate() {
|
| 133 |
}
|
| 134 |
|
| 135 |
function transformer_transforms_resize_perform($source, $destination, $data) {
|
| 136 |
return image_resize($source, $destination, $data['width'], $data['height']);
|
| 137 |
}
|
| 138 |
|
| 139 |
|
| 140 |
function transformer_transforms_fill_form($data) {
|
| 141 |
$form = array();
|
| 142 |
$form['fill_color'] = array(
|
| 143 |
'#type' => 'textfield',
|
| 144 |
'#title' => t('Fill color'),
|
| 145 |
'#size' => 15,'#maxlength' => 30,
|
| 146 |
'#default_value' => $data['fill_color'],
|
| 147 |
);
|
| 148 |
$form['#validate'] = array('transformer_transforms_fill_form_validate' => array());
|
| 149 |
return $form;
|
| 150 |
}
|
| 151 |
|
| 152 |
function transformer_transforms_fill_form_validate() {
|
| 153 |
}
|
| 154 |
|
| 155 |
function transformer_transforms_fill_perform($source, $destination, $data) { //*
|
| 156 |
_transformer_transforms_hex2rgb($data['fill_color'],$r,$g,$b);
|
| 157 |
return image_toolkit_invoke('fill', array($source, $destination, $r, $g, $b));
|
| 158 |
}
|
| 159 |
|
| 160 |
function transformer_transforms_rotate_info() {
|
| 161 |
return array(
|
| 162 |
'title' => t('Rotate'),
|
| 163 |
'mimes' => array('image/jpeg','image/gif','image/png'),
|
| 164 |
'extensions' => array('gif','jpg','jpeg','png'),
|
| 165 |
);
|
| 166 |
}
|
| 167 |
|
| 168 |
function transformer_transforms_rotate_form($data) {
|
| 169 |
$form = array();
|
| 170 |
$form['degrees'] = array(
|
| 171 |
'#type' => 'textfield',
|
| 172 |
'#size' => 15,'#maxlength' => 30,
|
| 173 |
'#title' => t('Degrees'),
|
| 174 |
'#default_value' => $data['degrees'],
|
| 175 |
);
|
| 176 |
$form['#validate'] = array('transformer_transforms_rotate_form_validate' => array());
|
| 177 |
return $form;
|
| 178 |
}
|
| 179 |
|
| 180 |
function transformer_transforms_rotate_form_validate() {
|
| 181 |
}
|
| 182 |
|
| 183 |
function transformer_transforms_rotate_perform($source, $destination, $data) {
|
| 184 |
return image_rotate($source, $destination, $data['degreess']);
|
| 185 |
}
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
/**
|
| 190 |
* Convert a hex string to it's rgb integer components
|
| 191 |
* $hex can be in the formats: '#ABC','ABC','#AABBCC','AABBCC'
|
| 192 |
*
|
| 193 |
*/
|
| 194 |
function _transformer_hex2rgb($hex, &$r, &$g, &$b) {
|
| 195 |
$hex = ltrim($hex,'#');
|
| 196 |
if (preg_match('/^[0-9a-f]{3}$/i',$hex)) {
|
| 197 |
// 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
|
| 198 |
$r = str_repeat($hex{0},2);
|
| 199 |
$g = str_repeat($hex{1},2);
|
| 200 |
$b = str_repeat($hex{2},2);
|
| 201 |
}
|
| 202 |
elseif (preg_match('/^[0-9a-f]{6}$/i',$hex)) {
|
| 203 |
// #FFAA33 or r=FF, g=AA, b=33
|
| 204 |
list($r,$g,$b) = str_split($hex,2);
|
| 205 |
}
|
| 206 |
else {
|
| 207 |
//error: invalide hex string, TODO: set form error..
|
| 208 |
return FALSE;
|
| 209 |
}
|
| 210 |
|
| 211 |
$r = hexdec($r);
|
| 212 |
$g = hexdec($g);
|
| 213 |
$b = hexdec($b);
|
| 214 |
return TRUE;
|
| 215 |
}
|
| 216 |
|
| 217 |
/**
|
| 218 |
* Verify the image module and toolkit settings.
|
| 219 |
* @todo: hook_requirements
|
| 220 |
*/
|
| 221 |
function _transformer_check_settings() {
|
| 222 |
// Sanity check : make sure we've got a working toolkit
|
| 223 |
if (!image_get_toolkit()) {
|
| 224 |
drupal_set_message(t('Make sure you have a working image toolkit installed and enabled, for more information see: %settings', array('%settings' => l(t('the settings page'), 'admin/settings'))), 'error');
|
| 225 |
return FALSE;
|
| 226 |
}
|
| 227 |
return TRUE;
|
| 228 |
}
|
| 229 |
|