Drupal: Checking to see if User Has Picture

avatar, drupal, image

Solution

    $user_load = user_load($node->uid);
    $picture = $user_load->picture ? $user_load->picture : variable_get('user_picture_default', ''); // 
    $imgtag = theme('imagecache', 'avatar_node', $picture, $user_load->name, $user_load->name); 
    $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
    print l($imgtag, 'u/'.$user_load->name, $attributes);

if you copy default picture to files directory, you can determine it via http://api.drupal.org/api/function/file_directory_path/6

Problem

I'm displaying the userpicture on a node with this code here: ``` <?php $user_load = user_load($node->uid); $imgtag = theme('imagecache', 'avatar_node', $user_load->picture, $user_load->name, $user_load->name); $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE); print l($imgtag, 'u/'.$user_load->name, $attributes); ?> ``` This works great, except if the user doesn't have a picture, in which case it looks strange. How do I load the default picture if the user doesn't have a picture. I don't believe I have access to $picture in this block. Thanks in advance.

Original source