Hi,

Just love your module, thank you.

Please, as the output of the user picture is rather large and would prefer my imagecache preset 'imagecache/profile_small' to show in latest visitors, how would I change ...

$output .= theme('user_picture', $account);

to show the small picture I've setup in imagecache.

I found a possible solution, but don't know how to implement it at: http://drupal.org/node/284364

Most appreciate and reply, and thank you.
Lilian

Comments

Witch’s picture

yep, that would be great!

*subscribe*

sanduhrs’s picture

Project: User Visits » ImageCache
Version: 6.x-1.3 » 6.x-2.0-beta6
Component: User interface » Documentation

That seems more like an issue for ImageCache project, so moving.

I think your question is answered in the docs [1].

If you want to add manually an image and apply an imagecache preset on it, you need to add a code snippet to the desired .tpl.php file:

<?php
print theme('imagecache', $preset, $image['filepath'], $alt, $title,  $attributes);
?>

So, replacing $output .= theme('user_picture', $account);
with something like $output .= theme('imagecache', 'YOUR_PREVIOUSLY_CREATED_PRESET', $account->picture, $alt, $title, $attributes);
should do the trick (untested).

vg

[1] http://drupal.org/node/163561

drewish’s picture

Status: Active » Fixed

that looks right to me.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jwilson3’s picture

The problem with the example in #2 is that if the user doesn't have an uploaded picture. It doesnt know where to get the default picture.

I assume you're using imagecache_profiles for user pictures. If not, then first and foremost, you should install imagecache_profiles , as it is built to handle this specific case.

Imagecache_Profiles module allows you to have three presets assigned for viewing profile images, but if you need to specify by hand in a template file or elsewhere... then, there are two ways to possibly handle it:

1) Use logic to set the default image if the profile has no image set:

$picture = !empty($account->picture) ? $account->picture : variable_get('user_picture_imagecache_profiles_default', '') ;
$output .= empty($picture) ? '' : theme('imagecache', 'YOUR_PREVIOUSLY_CREATED_PRESET', $picture, $alt, $title, $attributes); 

2) specify the imagecache_preset before calling user_picture. My preferred way (much less code, and logic).

$account->imagecache_preset = 'YOUR_PREVIOUSLY_CREATED_PRESET';
$output .= theme('user_picture', $account);
jrivelli’s picture

I did

<?php print $account->imagecache_preset = 'profile_picture';
$output .= theme('user_picture', $account); ?>

and it is displaying the text 'profile_picture' only. I obviously messed it up, what do I have out of order here?

jwilson3’s picture

@jrivelli. Two issues: You're printing the wrong statement, and this whole post from the OP down to here assumes $output .= line is located inside a function that actually returns the $output variable. If you wanted to print this directly to the screen, say in a template file, it would look like this:

$account->imagecache_preset = 'profile_picture';
print theme('user_picture', $account);
jrivelli’s picture

Sweet, thanks a ton man!

yngens’s picture

I am trying to output userpics of the node author of different size in the comments. We have $author and $comment->uid available in comment.tpl.php, but not $account. Can't figure out how to use

$account->imagecache_preset = 'profile_picture';
print theme('user_picture', $account);

in comment.tpl.php.

jwilson3’s picture

@yngens: Try using imagecache_profiles module, and configure it with the desired imagecache preset in the user settings administration page.

Then the $picture variable (avaliable in comment.tpl.php) will hold the correct image.

Berliner-dupe’s picture

Status: Closed (fixed) » Active

Hello,

can anyone help me plz - i dont understand this?

I have 3 Roles (girls, boys, groups) - every role must have a "default image" if the user dont uploaded an own user-picture.

Now i found in other thread the information that i must use theme_preprocess_user_picture for this.

I copy the code for this function from user.module to my template.php

function framework_preprocess_user_picture(&$variables) {
  $variables['picture'] = '';
  if (variable_get('user_pictures', 0)) {
    $account = $variables['account'];
    if (!empty($account->picture) && file_exists($account->picture)) {
      $picture = file_create_url($account->picture);
    }
    else if (variable_get('user_picture_default', '')) {
      $picture = variable_get('user_picture_default', '');
    }

    if (isset($picture)) {
      $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
      $variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
      if (!empty($account->uid) && user_access('access user profiles')) {
        $attributes = array(
          'attributes' => array('title' => t('View user profile.')),
          'html' => TRUE,
        );
        $variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
      }
    }
  }
}

But now the imagecache-presets from imagecache-profile will ignored for users with own user-picture. All picture on my sites (different views with different imagecahce-presets) use the original-size for this file now.

The second question is - how can i set the default picture when users dont upload own picture?

I checked

else if (variable_get('user_picture_default', '')) {
      $picture = variable_get('user_picture_default', 'sites/default/files/profile/dummy.jpg');
    }

but this dont work. Other problem will be - if it work - i think the imagecache-presets for this default-image will be ignored too or?

Can anyone help me plz - i have big understand-problems for this.

(Sorry for my bad english)

Regards Matthias

fizk’s picture

Status: Active » Closed (fixed)

Please reopen if this is still an issue with ImageCache 6.x-2.0-rc1.