How do I get the user avatar picture? I am working on a custom Drupal 8 theme and I am trying to get the user avatar picture on a variable and output somewhere in the HTML.

I have created this function to get the name &amp; email of the current user logged in like so:

#Function to get the user name value &amp; output in the HTML DOM
function tropical_preprocess_page(&amp;$variables){
  # gets current user name
  $user_logged_in_name = $variables['user']-&gt;getDisplayName();

  # creates value to ouput in the DOM &amp; capitalize first letter
  $variables['user_logged_in_name'] = ucfirst($user_logged_in_name);

  # gets user email
  $user_email = $variables['user']-&gt;getEmail();
  $variables['user_email'] = $user_email;
}


That worked perfectly! Now I am trying to get the user profile picture, but I am not able to do it. Any help will be appreciate it.
you can get Url it by   get('user_picture')-&gt;entity-&gt;url()( you can get URI too with get('user_picture')-&gt;entity-&gt;getFileUri()), So  

function tropical_preprocess_page(&amp;$variables){
  // gets current user name
  $user_logged_in_name = $variables['user']-&gt;getDisplayName();

  // creates value to ouput in the DOM &amp; capitalize first letter
  $variables['user_logged_in_name'] = ucfirst($user_logged_in_name);

  // gets user email
  $user_email = $variables['user']-&gt;getEmail();
  $variables['user_email'] = $user_email;

  // get user picture
  $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id())
  $variables['user_picture'] = $user-&gt;get('user_picture')-&gt;entity-&gt;url();

}


Additionally,  If you want to get the default image when the user account doesn't have an image associated, use the following code.

$field = \Drupal\field\Entity\FieldConfig::loadByName('user', 'user', 'user_picture');
$default_image = $field-&gt;getSetting('default_image');
$file = \Drupal::entityManager()-&gt;loadEntityByUuid('file', $default_image['uuid']);
$picture = file_create_url($file-&gt;getFileUri());