From 04f7c84d15e160770e94be4d01ee48737cbe5ccb Mon Sep 17 00:00:00 2001
From: Angus Mak <angus.mak@lullabot.com>
Date: Fri, 18 Sep 2015 11:45:42 -0400
Subject: [PATCH] Issue #1312220 by makangus: Add image-width and image-height
 tokens for file entity

---
 token.tokens.inc | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/token.tokens.inc b/token.tokens.inc
index f584bda..d5ac8be 100644
--- a/token.tokens.inc
+++ b/token.tokens.inc
@@ -178,6 +178,14 @@ 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.'),
+  );
 
   // User tokens.
   // Add information on the restricted user tokens.
@@ -982,6 +990,20 @@ 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;
       }
     }
   }
-- 
2.2.1

