Taxonomy Image: Associate Images with Taxonomy Terms

Description

The taxonomy image module allows site administrators to associate images with taxonomy terms. Once defined, this association allows Drupal themes or other PHP code to display images with site content. For example, the taxonomy_image module might be used to display a penguin with content about Linux, and a cheeseburger with content about junk food.

The module allows the Drupal administrator to create a one-to-one term-to-image relationship. With image display recursion, it is also possible to create a many-to-one relationship. This is useful if creating taxonomy hierarchies in which an entire tree of terms will use the same image. With recursion enabled, you only need to associate an image with the tree parent, and all children will automatically inherit the same image.

Features

  • Image configuration happens within existing admin/taxonomy menu structure.
  • Developers can add custom attributes to <img> markup when displaying images.
  • Allows one-to-one term-to-image relationships.
  • Allows many-to-one term-to-image relationships.
  • Admin-permitted users can disable the images.
  • Administrators can force images to be a standard size.
  • Utilizes core file.inc API.
  • Any kind of image that can be used with the <img> tag is allowed, including animated gifs.
  • Provides the image to Views, if it is installed.
  • Will use Imagecache to resize the image, if it is installed and configured.

Set Up

  • Standard Drupal module installation applies.
  • Requires the taxonomy module to be enabled.
  • Properly configure Drupal's built in file system support by following the directions at Administer >> Site configuration >> File settings. Taxonomy Image will create another directory within the default file directory.

Settings

The overall module settings are found at Administer >> Site configuration >> Taxonomy Image.

  • Picture image path - This is the subdirectory in your files directory (Administer >> Site configuration >> File settings) where the category pictures will be stored.
  • User "Disable" box description - This allows you to describe the per-user ability to disable Taxonomy Image display in a manner that your users will understand.
  • Resizing Options
    • Picture resizing options - Imagecache - If the Imagecache module is installed, you will have a set of radios to choose the default preset for resizing the images. If you select one of these presets, or provide one in your call, then Taxonomy Image will use Imagecache to process the image.
    • The following will be ignored if an Imagecache preset is chosen (either by default or at run time). However, if the Imagecache preset provided is "ORIGINAL," Taxonomy Image will use these, so they should be set.

    • Picture resizing options - Taxonomy Image - this radio box selection determines how large the category images will be.
      • Exact - pictures will be resized to exactly the specified dimension(s).
      • Not less than - pictures smaller than the specified size will be scaled up.
      • Not greater than - pictures larger than the specified size will be scaled down.
      • Disabled - pictures will not be resized; they will be displayed exactly as they are uploaded.
    • Picture height - Specify a height in pixels. See the "picture resize" option above.
    • Picture width - Specify a width in pixels. See the "picture resize" option above.
  • Add wrapper div tag - This option indicates whether to add a "<div>" tag to the image. This may be useful in lists where the images are not of the same width.
  • Recursive image display - This functionality is mostly useful if you have defined a hierarchical taxonomy in Drupal and multiple terms within a tree will share the same image. The taxonomy_image_display function will recursively search for an image to display, starting with the applicable term, then trying the term's parents.

    If you don't understand what this means, then it's a good idea to not enable it.

Permissions

The taxonomy_image.module provides three permissions:

  • 'access taxonomy images': allow user to see taxonomy images.
  • 'administer taxonomy images': allow user to configure taxonomy images.
  • 'can disable taxonomy images': allow user to disable taxonomy images.

Note that you need to enable the 'access taxonomy images' permission for users that should see the taxonomy images.

Setting Up the Vocabulary and Terms

Uploading images

With the taxonomy_image module enabled, images can be uploaded and associated with category terms at Administer >> Content management >> Categories >> Images (this is a tab called "Category images"). On that page you will find tables containing all your vocabularies and terms. Next to each term is a link titled "upload image," which you can click to upload an image for that term. After clicking that link, you will be taken to another page with a small "Add images" form. Using the "browse" button you can select your image then click "Save."

Continue this process to upload appropriate images for your category terms. Note that by default, images will be displayed at the size they were uploaded. Alternatively, you can go to settings page (described above) to force the display height and/or width of all taxonomy images.

Recursive image display

Taxonomy is a very powerful tool and one of Drupal's best. One of its features is providing the ability to create hierarchical vocabularies, with which you can build a tree of terms. It is possible that an entire tree of terms, or even just a branch of terms, are all about a similar subject and should all be associated with the same image. By going to Administer >> Site configuration >> taxonomy_image, you can enable "Recursive image display." With this option enabled, you only need to configure an image for the parent term, and all children will automatically inherit the same image (unless they are manually configured to display an alternative image).