Drupal 7 – Render user profile picture programmatically @ 1

Normally, there are 2 ways render the user profile picture programmatically in Drupal 7. But before i show you the code, i would like to introduce the profile picture setting @ admin/config/people/accounts/settings.

 

In the above setting page, you can define the profile picture size by selecting a proper Picture display style. In my case, the default image style is user-avatar.

Ok, let’s move back to today’s topic.

The following code will render the user profile picture with the image style set in the Picture display style under the Account settings page.

$user = user_load($uid);
print theme('user_picture', array('account' => $user));

 

Very straight forward, isn’t it? But how about if i want to have another image style other than the default one? Here you are. =)

$user = user_load($uid);
print theme('image_style', array('path' => $user->picture->uri, 'style_name' => '<image-style>'));

 

Done =)

Reference: StackOverflow – How to dispaly user avatar in Drupal 7?

3 thoughts on “Drupal 7 – Render user profile picture programmatically @ 1”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.