Hello,
I guess that combining Filefield Meta and Getid3 Library allows us to use many meta-informations from various media files through Drupal 6 -- I am especially interested in filesize, weight, width and height of a PNG or JPEG images... -- but I don't know how. For instance, can we use Tokens to get those informations and display them through a simple process (I'm not a coder) ? Do you know a place where one could fine some (understandable) documentation about that?

Comments

quicksketch’s picture

There isn't any documentation that I'm aware of other than the inline PHPdoc. You can use the field_file_load() function to load a file by its FID, then look at the contents of the file.

$file = field_file_load(10);
print_r($file);

However, for what you're wanting you don't even need filefield_meta.module at all, as you can easily get this information by using the image_get_info() function provided by core.

I'm not sure about where you'll actually be using this code though. You've asked about using tokens to display this information (indeed filefield_meta does provide tokens for all this information), but you don't say exactly what you're working with. What are you trying to accomplish?

ErwanF’s picture

Thanks for your reply. This is an example of what I would like to accomplish: Just after uploading a JPEG image, this image would be made downloadable by clicking on the following text, created "on the fly" by the system: [width] x [height] ([weight]). Ex: "800x600 pixels (2000 Ko)".

quicksketch’s picture

Just after uploading a JPEG image, this image would be made downloadable by clicking on the following text

So this is while the user is still on the node/x/edit or node/add/x page and not when viewing the created piece of content? You want this below the thumbnail preview (in ImageField) or somewhere else? Perhaps a mockup/screenshot would clarify all of this for me. Depending on where you want to show this link, it'll change what the answer is.

ErwanF’s picture

I don't need any thumbnail there, only a "simple" text link. And the text is made of some of the image properties. The idea is to build the hypertext link while the image is uploaded (or immediately after). One could see this link directly on the node/x/edit page then on the node/x page. Instead of having a link made on the name of the image (grabbed from the name of the jpeg file for instance; this is already easily achievable), the link is made of some image properties like width, height, weight... and link to the newly uploaded image file.

quicksketch’s picture

Gotcha, fortunately both these places are themed in the same place (as long as you're using the "Generic files" display formatter).

You can do this with the following:

- Open the filefield_formatter.inc file
- Copy the entire "theme_filefield_file" function to your theme's template.php file.
- Rename the function to [name_of_your_theme]_filefield_file()
- Clear the Drupal cache at admin/settings/performance (click the "Clear all Caches" button at the bottom).
- Modify the function to include height and width information.

You can get the height and width information by using the following:

if ($info = image_get_info($file['filepath'])) {
  $options['attributes']['title'] .= ' '. $info['width'] .'x'. $info['height'] .' '. t('pixels');
}
$options['attributes']['title'] .= ' '. format_size($file['filesize']);

Add this just before the return '<div class="filefield-file clear-block">'. $icon . l($link_text, $url, $options) .'</div>'; line.

ErwanF’s picture

Wow, thanks for this detailed answer, quicksketch, I'll try this as soon as possible.

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -height, -image, -tutorial, -Documentation, -token, -weight, -getid3, -information, -jpeg, -png, -filefield meta, -width

Automatically closed -- issue fixed for 2 weeks with no activity.