How to add CSS classes to a an image which belongs to a content type? I have a content type with an image field; I would like to add CSS classes to those images.

I have looked at the values of the $content variable in node.tpl.php via the dpm(), but I couldn't see any properties/keys related to classes or attributes. Maybe I just couldn't see them, or I didn't know where to look.

I would like to print something like &lt;img src="path-to-image" class="my-classes"&gt; by using print render($content['myimage_field']) in node.tpl.php.

I do not want to use external modules to accomplish this. Is there any theme functions I can override? How do I override them?
You can use hook_node_preprocess in your themes template.php file to add to the 'attributes' array for the node before the variables are sent to your node template. when your field gets built up into html it will then have your class.

If you enable the devel module you can add the following to template.php to see what this 'build array' which is used to render the node looks like.

function twt_preprocess_node(&amp;$vars) {

    dpm($vars);

}


To alter the classes added to your field use something like the following (though look to the above to find out if you are putting your class in the right place).

function twt_preprocess_node(&amp;$vars) {

    $vars['field_myimagefield']['#attributes']['class'][] = 'myclass';

}


Some useful reading:


Render Arrays in Drupal 7
Setting up variables for use in a template
hook_preprocess_HOOK (Drupal 7)