By ykyuen on
Hi all,
i could get the user picture by the following code
$user = user_load($uid);
print theme('user_picture', array('account' =>$user));
this will render the default user picture size. is there anyway i can apply my own image style(imagecache) on it?
Thanks.
Regards,
Kit
Comments
Try this code,print
Try this code,
print theme('user_picture', array('account' =>$user,'style_name' => 'content_highlighter'));Replace "content_highlighter" with your image style name.
thanks. but this does not
thanks. but this does not work.
You need to get the uri of
You need to get the uri of the picture.
That should be:
$user->picture[0]['uri']Then use the image_style_url (http://api.drupal.org/api/drupal/modules--image--image.module/function/i...) to get the full path to the image to a specific imagecache preset.
You could define the thumbnail style like this maybe:
Now you can print it using
<img src="<?php print $default_thumbnail; ?>" />i am using gravatar
i am using gravatar integration so i could not get the image path.
is there any other way to get the user picture with style?
So you are using external
So you are using external images?
Maybe try http://drupal.org/project/imagecache_external
Thanks. it works for gravatar
Thanks. it works for gravatar now after using imagecache_external. here is a sample code. i can get the path using the gravatar_get_gravatar()
is there an option that will
is there an option that will also include the correct width and heights from the style?
the width and height are set
the width and height are set in the image style
I did it like this
As described here
A slight change
I don't know if this will help anyone or if it was just for my use case, but I ended up having to make a slight tweak in the second parameter of the image_style_url, switching:
user->picture[0]['uri']to this:
user->picture->uriFor finding the correct
For finding the correct combination to grab your image(s) the devel module is simply invaluable! =)
Thanks for your reply, this
Thanks for your reply, this was very helpful. However I found that it did not cause the images to get regenerated into the cache. Using theme fixed my problem:
echo theme('image_style', array('style_name' => 'Large', 'path' => $user->picture->uri));Profile Default Image
This works great.
However I am having an issue getting it to display the default profile image if one has not been added for the user.
as
$user->pictureis null.
It throws a horrible error
Notice: Trying to get property of non-object in include()Any ideas how to combat this so that it displays the default image.
Many Thanks
You could add a simple check,
You could add a simple check, eg:
Thanks tecjam, that's the
Thanks tecjam, that's the method I ended up using.
I had wondered whether there was a way of having the theme function fall back to the default profile picture, if you told it you were theming a profile picture.
This is what worked for me
After a lot of struggling with this I place this code in my node--article.tpl.php template and it worked fine.
To achieve this in a Drupal way!
Hi Kit,
You can surely achieve this in a Drupal way using the following code, I've tried to mention as much as reference I can provide in the code with the help of comments.
Cheers!
I could only see the user picture, but no default picture
Here my solution that works for me:
I took the user object with db_query ...
and then:
Another way to get the default
Another way to get the default picture with less conditionals is to make the background of the div that contains the user picture the default image in CSS.
Then if the image is absent, it does not render but the background image is shown.
If it renders the background image is covered.
In your template.php
In your template.php
This should go in your .tpl.php file
global $user; if ($user->uid):echo $user_image;endif;Just override user picture style variable.
________________________
Override, don't change!