How can I display a user avatar in Drupal 7?
The code used from user_user_view() is the following one:

$account-&gt;content['user_picture'] = array(
  '#markup' =&gt; theme('user_picture', array('account' =&gt; $account)), 
  '#weight' =&gt; -10,
);


For example, if you want to output the HTML code to show the picture associated with the currently logged-in user in a form, you could use code similar to the following one:

$form['user_picture'] = array(
  '#theme' =&gt; 'user_picture',
  '#account' =&gt; $GLOBALS['user'], 
);


This is similar to the following code used in node_admin_nodes(), which uses a different theme function.

$form['nodes'] = array(
  '#theme' =&gt; 'table', 
  '#header' =&gt; $header, 
  '#rows' =&gt; $options, 
  '#empty' =&gt; t('No content available.'),
);


The content of "#header," "#rows," and "#empty" are used to populate the content of the $variables array that is passed to the theme function ("#header" becomes "header," etc). 

theme('user_picture') works even when the Image module (the one that defines theme_image_style()) is not enabled; in that case, it uses theme_image() instead. When the Image module is enabled, it uses the default style as contained in the Drupal variable "user_picture_style." In both the cases, the user image is a link to the user profile.  

As the theme function is using a template (user-picture.tpl.php), the relevant code is in template_preprocess_user_picture(); if you look at the code for theme_user_picture(), you would see there is no code.