diff --git a/token/token.tokens.inc b/token/token.tokens.inc index e0c0b5e..4a5a43b 100644 --- a/token/token.tokens.inc +++ b/token/token.tokens.inc @@ -178,6 +178,18 @@ function token_token_info() { 'name' => t('File byte size'), 'description' => t('The size of the file, in bytes.'), ); + $info['tokens']['file']['image-width'] = array( + 'name' => t('Image Width'), + 'description' => t('The width of the image file.'), + ); + $info['tokens']['file']['image-height'] = array( + 'name' => t('Image Height'), + 'description' => t('The height of the image file.'), + ); + $info['tokens']['file']['image-dimensions'] = array( + 'name' => t('Image Dimensions'), + 'description' => t('The dimensions (WxH) of the image file.'), + ); // User tokens. // Add information on the restricted user tokens. @@ -982,6 +994,27 @@ function token_tokens_alter(array &$replacements, array $context) { $replacements[$original] = $sanitize ? check_plain($name) : $name; } break; + + case 'image-width': + $image_info = image_get_info(drupal_realpath($file->uri)); + if ($image_info && $image_info['width']) { + $replacements[$original] = $image_info['width']; + } + break; + + case 'image-height': + $image_info = image_get_info(drupal_realpath($file->uri)); + if ($image_info && $image_info['height']) { + $replacements[$original] = $image_info['height']; + } + break; + + case 'image-dimensions': + $image_info = image_get_info(drupal_realpath($file->uri)); + if ($image_info && $image_info['width'] && $image_info['height']) { + $replacements[$original] = $image_info['width'] . "x" . $image_info['height']; + } + break; } } }