The following patch adds support for including WIDTHxHEIGHT in the filenames upon upload.

@@ -498,6 +498,10 @@ function filefield_paths_token_info() {
     'name' => t("File extension - original"),
     'description' => t("File extension - original."),
   );
+  $info['tokens']['file']['ffp-dimensions'] = array(
+    'name' => t("Image dimensions"),
+    'description' => t("Image dimensions, WIDTHxHEIGHT"),
+  );
   return $info;
 }

@@ -535,6 +539,18 @@ function filefield_paths_tokens($type, $tokens, array $data = array(), array $op
           $info = pathinfo($file->origname);
           $replacements[$original] = $info['extension'];
           break;
+          
+        case 'ffp-dimensions':
+          $dimensions = '';
+          $filemime = explode('/', $file->filemime);
+          if ($filemime[0] == 'image') {
+            $image_info = image_get_info(drupal_realpath($file->uri));
+            if ($image_info['width'] && $image_info['height']) {
+              $dimensions = $image_info['width'] .'x'. $image_info['height'];
+            }
+          }
+          $replacements[$original] = $dimensions;
+          break;
       }
     }
   }
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Deciphered’s picture

Project: File (Field) Paths » Token

Hi robphillips,

FileField Paths is not the appropriate place for these tokens, as they are specific to one particular use case provided by one particular module, the Image module. As the Image module is Drupal Core, I'm recommending that this request should be in the Token module instead.

I am moving this request there on your behalf.

Cheers,
Deciphered.

Dave Reid’s picture

Title: Include dimensions (WIDTHxHEIGHT) in available token replacements » Add image width and height tokens for files (add an image token type?)
Priority: Major » Normal

Yeah it probably makes sense to add an image-width and an image-height token for files. Maybe we need to have an [image:*] token type that extends the file token type.

El Matador Y Tyrannos’s picture

Hi !

Any plans about a specific image token type ?
A really nice feature would be the support of image styles for any image fields from any entity types...

Like this module, but it only provides support for nodes :
http://drupal.org/project/imagecache_token

Thanks !

makangus’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.68 KB
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View

How about this?

  • Add [file:image-width] and [file:image-height]
  • Calling them image-width and image-height instead of width and height to be more explicit, since not all files are images
le72’s picture

Hello, I actually need dimensions and sizes. So merged last to patches. Please review.

chrowe’s picture