| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function image_image_effect_info() {
|
| 13 |
|
| 14 |
|
| 15 |
'label' => t('Resize'),
|
| 16 |
'help' => t('Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.'),
|
| 17 |
'effect callback' => 'image_resize_effect',
|
| 18 |
'form callback' => 'image_resize_form',
|
| 19 |
'summary theme' => 'image_resize_summary',
|
| 20 |
),
|
| 21 |
|
| 22 |
'label' => t('Scale'),
|
| 23 |
'help' => t('Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.'),
|
| 24 |
'effect callback' => 'image_scale_effect',
|
| 25 |
'form callback' => 'image_scale_form',
|
| 26 |
'summary theme' => 'image_scale_summary',
|
| 27 |
),
|
| 28 |
|
| 29 |
'label' => t('Scale and crop'),
|
| 30 |
'help' => t('Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.'),
|
| 31 |
'effect callback' => 'image_scale_and_crop_effect',
|
| 32 |
'form callback' => 'image_resize_form',
|
| 33 |
'summary theme' => 'image_resize_summary',
|
| 34 |
),
|
| 35 |
|
| 36 |
'label' => t('Crop'),
|
| 37 |
'help' => t('Cropping will remove portions of an image to make it the specified dimensions.'),
|
| 38 |
'effect callback' => 'image_crop_effect',
|
| 39 |
'form callback' => 'image_crop_form',
|
| 40 |
'summary theme' => 'image_crop_summary',
|
| 41 |
),
|
| 42 |
|
| 43 |
'label' => t('Desaturate'),
|
| 44 |
'help' => t('Desaturate converts an image to grayscale.'),
|
| 45 |
'effect callback' => 'image_desaturate_effect',
|
| 46 |
),
|
| 47 |
|
| 48 |
'label' => t('Rotate'),
|
| 49 |
'help' => t('Rotating an image may cause the dimensions of an image to increase to fit the diagonal.'),
|
| 50 |
'effect callback' => 'image_rotate_effect',
|
| 51 |
'form callback' => 'image_rotate_form',
|
| 52 |
'summary theme' => 'image_rotate_summary',
|
| 53 |
),
|
| 54 |
);
|
| 55 |
|
| 56 |
return $effects;
|
| 57 |
}
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
function image_resize_effect(&$image, $data) {
|
| 74 |
if (!image_resize($image, $data['width'], $data['height'])) {
|
| 75 |
watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 76 |
return FALSE;
|
| 77 |
}
|
| 78 |
return TRUE;
|
| 79 |
}
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
function image_scale_effect(&$image, $data) {
|
| 98 |
|
| 99 |
|
| 100 |
'upscale' => FALSE,
|
| 101 |
);
|
| 102 |
|
| 103 |
|
| 104 |
$data['width'] = empty($data['width']) ? PHP_INT_MAX : $data['width'];
|
| 105 |
$data['height'] = empty($data['height']) ? PHP_INT_MAX : $data['height'];
|
| 106 |
|
| 107 |
if (!image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
|
| 108 |
watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 109 |
return FALSE;
|
| 110 |
}
|
| 111 |
return TRUE;
|
| 112 |
}
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
function image_crop_effect(&$image, $data) {
|
| 133 |
|
| 134 |
|
| 135 |
'anchor' => 'center-center',
|
| 136 |
);
|
| 137 |
|
| 138 |
list($x, $y) = explode('-', $data['anchor']);
|
| 139 |
$x = image_filter_keyword($x, $image->info['width'], $data['width']);
|
| 140 |
$y = image_filter_keyword($y, $image->info['height'], $data['height']);
|
| 141 |
if (!image_crop($image, $x, $y, $data['width'], $data['height'])) {
|
| 142 |
watchdog('image', 'Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 143 |
return FALSE;
|
| 144 |
}
|
| 145 |
return TRUE;
|
| 146 |
}
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
function image_scale_and_crop_effect(&$image, $data) {
|
| 163 |
if (!image_scale_and_crop($image, $data['width'], $data['height'])) {
|
| 164 |
watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 165 |
return FALSE;
|
| 166 |
}
|
| 167 |
return TRUE;
|
| 168 |
}
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
function image_desaturate_effect(&$image, $data) {
|
| 182 |
if (!image_desaturate($image)) {
|
| 183 |
watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 184 |
return FALSE;
|
| 185 |
}
|
| 186 |
return TRUE;
|
| 187 |
}
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
function image_rotate_effect(&$image, $data) {
|
| 209 |
|
| 210 |
|
| 211 |
'degrees' => 0,
|
| 212 |
'bgcolor' => NULL,
|
| 213 |
'random' => FALSE,
|
| 214 |
);
|
| 215 |
|
| 216 |
|
| 217 |
if (strlen($data['bgcolor']) == 4) {
|
| 218 |
$c = $data['bgcolor'];
|
| 219 |
$data['bgcolor'] = $c[0] . $c[1] . $c[1] . $c[2] . $c[2] . $c[3] . $c[3];
|
| 220 |
}
|
| 221 |
|
| 222 |
|
| 223 |
if ($data['bgcolor'] != '') {
|
| 224 |
$data['bgcolor'] = hexdec(str_replace('#', '0x', $data['bgcolor']));
|
| 225 |
}
|
| 226 |
|
| 227 |
$data['bgcolor'] = NULL;
|
| 228 |
|
| 229 |
|
| 230 |
if (!empty($data['random'])) {
|
| 231 |
$degrees = abs((float)$data['degrees']);
|
| 232 |
$data['degrees'] = rand(-1 * $degrees, $degrees);
|
| 233 |
}
|
| 234 |
|
| 235 |
if (!image_rotate($image, $data['degrees'], $data['bgcolor'])) {
|
| 236 |
watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['height'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
| 237 |
return FALSE;
|
| 238 |
}
|
| 239 |
return TRUE;
|
| 240 |
}
|
| 241 |
|