Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#5 | token_image-width-height-dimenstion_1312220-5.patch | 1.83 KB | le72 |
#4 | token-add-image-width-height-1312220.patch | 1.68 KB | makangus |
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedHi 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 CreditAttribution: 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 CreditAttribution: makangus commentedHow about this?
Comment #5
le72Hello, I actually need dimensions and sizes. So merged last to patches. Please review.
Comment #6
chrowe CreditAttribution: chrowe at Isovera commentedI think https://www.drupal.org/project/imagecache_token handles this.