After reading the documentation, it seems that the correct way of doing that is like this:

php print $user_picture;

It won't work (it doesn't print anything at all).

Afetr asking around, I get this answer, which sadly won't work either:

global $user;
$image = theme('user_picture', $user);
print $image

That code was suggested as a "last resource", but when I try to use it, I get this error message:

Fatal error: Cannot use object of type stdClass as array in /includes/theme.inc on line 1054

Line 1054 is the following one:

  // Line 1054
  if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
    $element = $variables;
    $variables = array();
    if (isset($info['variables'])) {
      foreach (array_keys($info['variables']) as $name) {
        if (isset($element["#$name"])) {
          $variables[$name] = $element["#$name"];

It´s pretty clear that it should work, but it doesn't.

Using contemplate module, I get this output as an alternative, but it doesn't work either.

<?php print $node->picture ?>

I've tried then with Devel module (using the /devel tab of the node):

I get this:

picture (String, 4 characters ) 2876

Wich won't work, because the output is just "2876", but is the only "picture" there.

So what can I do? How can I trace this problem?


Have you tried examining the $user object itself? It should be something like

    global $user;
    print $user->picture;

Or if that is loading the logged in user(which it will) as opposed to the user(creator of the node) you are viewing try on a node:

$user_object = user_load($uid));
print $user_object->picture;
| improve this answer | |
  • Thanks for your reply! I don´t have a custom profile image, so it should output the default one (as it outputs in the comments), but the output is 0. (cero, the number). In the second case, it outputs nothing.I´ve have the output of dsm($content) here: imageshack.us/photo/my-images/69/issuej.jpg – Rosamunda Aug 18 '12 at 14:23

I´ve got it! It was really something silly now that I´ve found it :) Just in case anyone out there wonders: Under /admin/structure/types/manage/{nodetype} you have this option: "Display author and date information". That option has to be checked.

I´ve checked that users were able to have pictures (the option "enable user pictures", under /admin/config/people/accounts), but in D7 there´s this option under each content type...

Hope this helps someone.

| improve this answer | |

The reason theme('user_picture', $user) is not working is that theme_user_picture() is expecting an array, but you are passing an object. That is exactly what the error message is telling you.

The right way to call theme_user_picture() is the following one.

$image = theme('user_picture', array('account' => $GLOBALS['user']));

As evident in template_preprocess_user_picture() code, the theme function will return the markup for the picture if the content of the Drupal variable "user_pictures" doesn't evaluate to FALSE. Differently, the theme function will return an empty string, which also what happens if Drupal is not able to load the user's image, or the default image set for users.

Notice also that what returned from the theme function is not merely the markup for an image; if the user has the permission to access user profiles, the image is also a link to the user profile. If you just need to output the markup for the image, then you need to use your own code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.