I created a content type that includes a user reference field. The view is properly handing that, even with my rewrite to add "/contact" on the end of the link. But I'd really prefer add the (styled) user picture as well. Is there any way to do that?

Files: 
CommentFileSizeAuthor
#10 user_picture_styles.patch3.48 KBquicksketch
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch user_picture_styles.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

You should be able to add a relationship from that user reference; once you do, all user fields will become available.

Status:Active» Fixed

Status:Fixed» Active

Is there no way to apply an image style?

Category:support» task

Since it's in drupal core this is could be a feature of views.

Status:Active» Fixed

It's not possible to do nice but you can use hook_preprocess_user_picture for yourself.

Thanks, Earl and Daniel.

If you want to see why, look here:

      // don't load image styles.
      if (module_exists('image') && file_valid_uri($filepath) && $style = variable_get('user_picture_style', '')) {
        $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
      }

Status:Fixed» Postponed

Thanks again.

Title:User reference field: How to show user pictureSupport image styles in the User: Picture field
Category:task» feature
Status:Postponed» Needs review
StatusFileSize
new3.48 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch user_picture_styles.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I've read up on #1021564: Allow to set image style when using theme('user_picture') and the duplicate issue here: #999050: User: Picture field does not support Image Styles.

Given our situation of waiting on core for a feature that might never come, I'd prefer to implement this feature based on what we have right now. I think #1292470: Convert user pictures to Image Field is more likely to happen before theme_user_picture() takes an image style option, in which case the chance of D7 backport becomes very slim. Even though the foundation for user pictures in core is not ideal, I think making Views support all the abilities core provides out-of-the-box is desirable. Right now a site I'm building is in an awkward situation of using the D7 port of ImageCache Profiles just to get image style support into Views. That shouldn't be necessary.

This patch imitates portions of theme_user_picture() but avoids all the style-specific markup (the alt tags, title text, classes, etc.) If users want to theme their output, they can continue to do that by using the default style and theming it, or rewrite the link, or using a real image field as others have suggested.

Even though the user picture ability in D7 is inferior to a "real" image field, it's what we have in D7. For the sake of theme developers and for new users, I think including more complete support for user pictures should be included in Views.

Status:Needs review» Reviewed & tested by the community

Patch applies clean and adds a dropdown here:

The desired effect is accomplished as well. When I change the image style on the field, the preview shows the profile image through that image style.

I'm wondering if this should go within the 'Style Settings' fieldset though.

Status:Reviewed & tested by the community» Fixed

Yeah, that's cool that' someone took this and implemented it, so this works more or less.

I'm wondering whether it would be possible to still use theme_user_picture if you alter the path to the image.

Commited to 7.x-3.

Oh geez, I totally just looked at the screenshot and realized I'd labeled the new field "Image preset", doh! That should be "Image style". Everywhere else in the patch is correct, just a little relapse into D6 terminology.

Thanks dereine for your excellent responsiveness. I'll try to reroll tonight.

@quicksketch

Just changed this string

diff --git a/modules/user/views_handler_field_user_picture.inc b/modules/user/views_handler_field_user_picture.i
index 1674dd9..a603f4e 100644
--- a/modules/user/views_handler_field_user_picture.inc
+++ b/modules/user/views_handler_field_user_picture.inc
@@ -43,7 +43,7 @@ class views_handler_field_user_picture extends views_handler_field {
       }
       $form['image_style'] = array(
-        '#title' => t('Image preset'),
+        '#title' => t('Image style'),
         '#description' => t('Using <em>Default</em> will use the site-wide image style for user pictures set in
         '#type' => 'select',
         '#options' => $style_options,

Status:Fixed» Needs work

As maintainer of imagecache_profiles module I'd like to point that access to user profile should have access check.

Also what is a diffence with previous attempt #750172: User picture always links to user profile

@andypost
The two issues are fundamental different. This one is about choosing and image style, the other issue was about disabling the link.

You are right, that this addition needs some improvements.

Status:Needs work» Fixed

As maintainer of imagecache_profiles module I'd like to point that access to user profile should have access check.

Doesn't it already?

+        if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
+          $uid = $this->get_value($values, 'uid');
+          $output = l($output, "user/$uid", array('html' => TRUE));
+        }

+++ b/modules/user/views_handler_field_user_picture.incundefined
@@ -33,20 +34,60 @@ class views_handler_field_user_picture extends views_handler_field {
+      if (file_valid_uri($picture_filepath)) {

This would cause a lot of discussions like #1107464: user default image doesn't get formatted
This realy does not work if path like ./themes/bartik/logo.png

Let's continie discussion in #1021564: Allow to set image style when using theme('user_picture')

Check the API: This function is never used; see the corresponding template file instead.

@NancyDru: If you were referring to my comment above, "This patch imitates portions of theme_user_picture()", you're right. Calls to theme('user_picture') call template_preprocess_user_picture() and then use the user-picture.tpl.php file. But I don't see what you intended by your comment.

Status:Fixed» Closed (fixed)

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

Category:feature» bug
Status:Closed (fixed)» Needs review

Just selected my custom image style which scales and crops the default user picture size of 85x85 down to 40x40.

Selecting 'Default' image style from the drop down works, selecting any other image style (including my custom 40x40 style) results in the image not being rendered.

Using D7.20 and Views 3.5

Anyone else experiencing this problem?

S

Status:Needs review» Needs work

The last submitted patch, user_picture_styles.patch, failed testing.

I face the same issue - when I choose another preset than "Standard" the image field is rendered empty when viewing the views page:

<div class="field-content"></div>

Using views 7.x-3.5

Ok, I found out the following:

In views/modules/user/views_handler_field_user_picture.inc in line 88 the if-check fails:

      if (file_valid_uri($picture_filepath)) {
        $output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
        if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
          $uid = $this->get_value($values, 'uid');
          $output = l($output, "user/$uid", array('html' => TRUE));
        }
      }

As I found out file_valid_uri() checks if the URI has a valid scheme. I have a public files system so I simply hardcoded such an URI to see if it works - and it worked:

$picture_filepath = 'public://pictures/profilbild/picture-5575.jpg';
      if (file_valid_uri($picture_filepath)) {
        $output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
        if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
          $uid = $this->get_value($values, 'uid');
          $output = l($output, "user/$uid", array('html' => TRUE));
        }
      }

Does anyone know how you get the URI with scheme instead of the pictures path from drupal root?

For me I found a maybe hackish solution... I am not a professional programmer but for know this works for me... I did not find out how you get the stream of a file so I simply did it this way:

Before line 88:

      $system_path = substr($picture_filepath,0,19);
      if ($system_path == 'sites/default/files') { // check if file is the public folder
        $picture_filepath = str_replace('sites/default/files/', '', $picture_filepath);
        $picture_filepath = 'public://'. $picture_filepath;
      }
      if (file_valid_uri($picture_filepath)) {
        $output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
        if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
          $uid = $this->get_value($values, 'uid');
          $output = l($output, "user/$uid", array('html' => TRUE));
        }
      }

The module https://drupal.org/project/default_user_picture_styles attempts to solve this problem.