How to rewrite the ouput html of the image field for a node page? I have an image field where people can upload an unlimited number of photos to a node. By default, drupal 7 outputs these images with html similar to the following:

&lt;div class="field-items"&gt;
    &lt;div class="field-item even"&gt;
        &lt;a rel="gallery-170" class="colorbox init-colorbox-processed-processed cboxElement" title="" href="http://tourismbuilder1.hokkaido-select.com/sites/default/files/gaikan_5.jpg"&gt;

            &lt;img width="580" height="386" title="" alt=""&gt;


This is fine, but for my application, I would like to be able to print a unique number to identify the image in the class or as an id - so, instead of field-item even, field-item-012 even, for example.  Should this be done in the template file or in template.php file?

Thanks!
This looks like output coming from theme('field') theme function in field.module. You can override the output by putting the following function in your template.php:

/**
 * Implements template_preprocess_field
 */
function mythemename_preprocess_field(&amp;$vars) {

}


More info on the preprocessor (with examples of how to add additional classes) is here: template_preprocess_field

EDIT:
Actually looking at the theme function, it seems that in your case I think you need to implement both a preprocessor and a template file for your field. So in the preprocessor you create a variable for the class:

/**
 * Implements template_preprocess_field
 */
function mythemename_preprocess_field(&amp;$vars) {
  $element = $vars['element'];
  if ($element['#field_name'] == 'field_myfieldname') {
    $number = 123; // This variable should get the value you wish to attach to the class
    $vars['field_myfieldname_custom_class'] = 'field-item-' . $number;
  }
}


And then create a field template file field--field_myfieldname.tpl.php and put &lt;?php print $field_myfieldname_custom_class; ?&gt; where the class should appear.