How do I get the default user picture? I am using the following code to get the URL of the image associated to a user.

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


If the user didn't upload a picture, this code doesn't return anything useful.

How can I get the URL for the default image?
User pictures are no longer guaranteed to exist in Drupal 8. It is added by the standard profile, but not added if you use the minimal profile.

The user picture is simply a image field attached to the user bundle, so normal file field API's can be used. To get the file path of the default image for the user picture field attached to the user bundle:

&lt;?php
$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']);
$file-&gt;getFileUri();
?&gt;


I'm not sure what you are trying to achieve. If you are looking for better default avatars, then I encourage you to look at Avatar Kit for Drupal 8. Disclaimer: I am the developer of Avatar Kit.