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;
}
}
}
Comments
Comment #1
decipheredHi 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.
Comment #2
dave reidYeah 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.
Comment #3
Bitou Deouf commentedHi !
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 !
Comment #4
makangus commentedHow about this?
Comment #5
le72Hello, I actually need dimensions and sizes. So merged last to patches. Please review.
Comment #6
chrowe commentedI think https://www.drupal.org/project/imagecache_token handles this.