logo

Programmatically get user picture/image in Drupal 8 or 9

16
December

Programmatically get user picture/image in Drupal 8 or 9
By: Anonymous | Published On: Thu, 12/16/2021 - 07:53

Following code can be used to get user picture or image by loading user data in Drupal 8

$user = \Drupal\user\Entity\User::load($uid);
$imgpath = $user->get('user_picture')->entity->uri->value;
if(!empty($imgpath)){
	$user_pic = file_create_url($picurl);
}

Need Help ?