How to display the default user picture programatically? I'd like to print a user's image in a View's template file. If the user hasn't set an image yet, the default user picture (set to public://pictures/default.jpg at Configuration &gt; People &gt; Account settings) should be rendered.

I used the following code:

&lt;?php $account = user_load($user-&gt;uid); ?&gt;
&lt;?php if (isset($account-&gt;picture-&gt;uri)) {
          $path = $account-&gt;picture-&gt;uri; }
      else {$path = "public://pictures/default.jpg"; } ?&gt;
&lt;?php $array = array('style_name' =&gt; 'picture',
                     'path' =&gt; $path,
                     'alt' =&gt; 'Picture'); ?&gt;
&lt;div class="user-image"&gt;&lt;?php print theme('image_style', $array); ?&gt;&lt;/div&gt;


That works perfectly, but I don't really like the isset approach, because it makes me think that it was redundant to specify the default image path in the configurations. Is there another method that uses the default path automatically?
It's a bit of a strangled route - Drupal itself uses some conditionals in template_preprocess_user_picture() to make that decision:

if (!empty($account-&gt;picture)) {
  // @TODO: Ideally this function would only be passed file objects, but
  // since there's a lot of legacy code that JOINs the {users} table to
  // {node} or {comments} and passes the results into this function if we
  // a numeric value in the picture field we'll assume it's a file id
  // and load it for them. Once we've got user_load_multiple() and
  // comment_load_multiple() functions the user module will be able to load
  // the picture files in mass during the object's load process.
  if (is_numeric($account-&gt;picture)) {
    $account-&gt;picture = file_load($account-&gt;picture);
  }
  if (!empty($account-&gt;picture-&gt;uri)) {
    $filepath = $account-&gt;picture-&gt;uri;
  }
}
elseif (variable_get('user_picture_default', '')) {
  $filepath = variable_get('user_picture_default', '');
}


If it suits your use case, you can just set the user_picture_style variable to your style name, and use theme_user_picture():

$build = array(
  '#theme' =&gt; 'user_picture',
  '#account' =&gt; $user,
);
$picture = drupal_render($build);


The caveat is that user_picture_style is a global var, so if you want to use something different for the style used elsewhere in the site, you're stuck with reproducing the same logic as the preprocess function above.