What's the easiest way to resize $user->picture?
ajwwong - April 17, 2006 - 17:54
Hi everyone!
I've got user pictures uploaded onto my site through $user->picture, but I want to sometimes display the picture at "full size", sometimes at "thumbnail", and sometimes at "mini" (20x20px) size. Is there an easy way to do this through drupal? [Like something like theme($user->picture,'large') or something like that?]
All help appreciated.
Thanks!
Albert
www.ithou.org

Well, I'm still working on this... thought I'd post my latest...
So... I'm still trying to format my "user_picture" differently, depending on the context of where it shows up -- for example, I want to have the user_picture be "miniaturized" when it shows up with comments, but *big* when it shows up on the user_profile page.
If anyone has any ideas, I'd still love to hear them...
Anyhow, right, now I've been looking at these different functions... apparently, you can possibly theme the user_picture differently for node, user, block... tho-- I'm still figuring out how this all works... for example... I've seen these kinds of functions in code, so there may be a way of doing this after all... :-)
theme('user_picture',$node);
theme('user_picture',$user);
theme('user_picture',$account);
theme('user_picture',$block);
theme('user_picture',$comment);
I'll post here if I figure it out.
Albert
www.ithou.org
Like the idea...
I like the idea... Maybe you could start a feature request, to where the theme can decide what it wants. You might take a look at image.module, because it uses a thumbnail, medium size, and the original size for images, and other sizes are configurable.
Another option I'd like to see is to allow the user's picture to be displayed in certain node types, as in the forum only. This can be done with the theme, but it's a hack, and not one I like to use. That's a whole new topic though...
--
Bradlis7.com | Churchofchristnet
so,I have looked at the image.module briefly
and it looks as if the image module actually loads up the entire picture, and then resizes it -- so I have decided that that might be a bit too bandwidth intensive to load up the entire picture, especially if all I want is a mini version of it.
So, currently I'm looking into the following strategy: I am trying to save three different copies of the user_picture -- a full-size , a regular one for the icon, and a mini version of it -- during the user_picture_validate function -- i.e., when the user first uploads the picture. However, I am having a difficult time with it.
it seems as if once you use file_save_upload, you cannot use it again -- that is, once you have "saved" the file that you've uploaded, you cannot "re-save" it-- for example, at a different magnification. if anyone has any ideas on how to "re-save" a file that you have already "saved" through file_save_upload, I would love to hear them.
Thanks,
Albert
www.ithou.org
In case anyone is interested in this, here is the current state of my (non-functioning) code-- this is a hack to user.module's user_picture_validate function:
<?php
function user_validate_picture($file, &$edit, $user) {
global $form_values;
// Initialize the picture:
$form_values['picture'] = $user->picture;
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$info = image_get_info($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if (!$info || !$info['extension']) {
form_set_error('picture_upload', t('The uploaded file was not an image.'));
}
else if (image_get_toolkit()) {
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
}
else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
if (!form_get_errors()) {
// **************my hack begins here -- ajwwong *************************
$file_icon = $file; // I am storing a copy of $file for the different sizes of $user->picture I want to eventually manipulate
$file_mini = $file;
//These next two lines were here before, and work OK -- that is the file gets saved appropriately as your regular old user picture-- ajwwong */
if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . '.' . $info['extension'], 1)) {
$form_values['picture'] = $file->filepath;
//*however, when I try to scale the images and add these next lines below to create *different sized* user pictures-- for some reason, the file does not ultimately get saved --ajwwong
$file = $file_icon;
$maxwidth_icon = 50;
$maxheight_icon = 50;
image_scale($file->filepath, $file->filepath, $maxwidth_icon, $maxheight_icon);
$file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/pictureicon-'. $user->uid . '.' . $info['extension'], 1);
/*print_r($file_icon);
print_r($file_mini);
print_r($file);*/
$file = $file_mini;
$maxwidth_mini = 20;
$maxheight_mini = 20;
image_scale($file->filepath, $file->filepath, $maxwidth_mini, $maxheight_mini);
$file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picturemini-'. $user->uid . '.' . $info['extension'], 1);
/*print_r($file_icon);
print_r($file_mini);
print_r($file);*/
// Adding these lines above to create *different sized* user pictures!! but it does not actually save the pictures correctly, or at all. ajwwong 4.23.06 */
// **************my hack ends here -- ajwwong *************************
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => '<em>'. variable_get('user_picture_path', 'pictures') .'</em>')));
}
}
}
?>
It makes sense that
It makes sense that file_save_image would move the file, because it would leave a dangling file if not.
I think changing this line,
<?phpelse if (image_get_toolkit()) {
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
?>
to make it scale the other two images to a new destination beforehand would do the job.
<?php
else if (image_get_toolkit()) {
/* added */
$maxwidth_icon = 50;
$maxheight_icon = 50;
image_scale($file->filepath, variable_get('user_picture_path', 'pictures') .'/pictureicon-'. $user->uid . '.' . $info['extension'], $maxwidth_icon, $maxheight_icon);
$maxwidth_mini = 20;
$maxheight_mini = 20;
image_scale($file->filepath, variable_get('user_picture_path', 'pictures') .'/picturemini-'. $user->uid . '.' . $info['extension'], $maxwidth_mini, $maxheight_mini);
/* kept same */
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
?>
Here's a cleaned up version:
<?php
function user_validate_picture($file, &$edit, $user) {
global $form_values;
// Initialize the picture:
$form_values['picture'] = $user->picture;
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$info = image_get_info($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if (!$info || !$info['extension']) {
form_set_error('picture_upload', t('The uploaded file was not an image.'));
}
else if (image_get_toolkit()) {
/* added */
$maxsize_icon = array('w'=>50,'h'=>50); //clean up
image_scale($file->filepath, variable_get('user_picture_path', 'pictures') .'/pictureicon-'. $user->uid . '.' . $info['extension'], $maxsize_icon['w'], $maxsize_icon['h']);
$maxsize_mini = array('w'=>20, 'h'=>20);
image_scale($file->filepath, variable_get('user_picture_path', 'pictures') .'/picturemini-'. $user->uid . '.' . $info['extension'], $maxsize_mini['w'], $maxsize_mini['h']);
/* end add */
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
}
else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
if (!form_get_errors()) {
if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . '.' . $info['extension'], 1)) {
$form_values['picture'] = $file->filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => '<em>'. variable_get('user_picture_path', 'pictures') .'</em>')));
}
}
}
?>
I haven't tested it, but logically, I think it will work. It copies the image at the same time as resizing it.
--
Bradlis7.com | Churchofchristnet
holy kamole!
that's *way* beyond the call of duty... thanks so much bradlis! I'll definitely give that a shot and report back! :-) It looks really good so far...
Thanks again!
Albert
www.ithou.org
Well... not working, yet...
I'm getting the following warning when I try the code above...
Warning: imagejpeg(): Unable to open 'pictures/pictureicon-6.jpg' for writing in /home/ithou/public_html/includes/image.inc on line 300
Warning: imagejpeg(): Unable to open 'pictures/picturemini-6.jpg' for writing in /home/ithou/public_html/includes/image.inc on line 300
Warning: Cannot modify header information - headers already sent by (output started at /home/ithou/public_html/includes/image.inc:300) in /home/ithou/public_html/includes/common.inc on line 265
I've checked my permissions in my "pictures" directory, and it's set to 777 -- read, write, execute -- so I don't think it's a permissions issue.
Hmmm... well, I'll try the file_move idea you wrote about in the other post. Thanks again!
Albert
www.ithou.org
Possible this issue?
Image module don't create thumbnail and preview images, original is OK
--
My first drupal site - http://www.enigma.sk/kope-vas-muza/ (now developing)
So, an easy work around
So, an easy work around might be to copy the file to the necessary location, and resize it, using the same $source and $destination.
<?php$icon = $file; //file_copy changes the value of the variable
if(file_copy($icon, variable_get('user_picture_path', 'pictures').'/pictureicon-'. $user->uid . '.' . $info['extension']))
image_scale($icon->filepath, $icon->filepath, $maxsize_icon['w'], $maxsize_icon['h']);
?>
--
Bradlis7.com | Churchofchristnet
Bingo!!!
That did it bradlis!!
Perfectomundo....
Thanks so much... that's perfect... !!
Blessings to you,
Albert
www.ithou.org
OK, so... I did it!! --- with help from bradlis7 & others
4.7 tested only
Here's the steps... much thanks to bradlis for guiding the way... it actually involves a hack to user.module... but, well, ya only live once... There might be a better way... -- in fact, on second thought, I should have perhaps made more use of image.module as bradlis had initially suggested, but I couldn't figure out the _produce_image_derivatives functionality of that module... If I had to do it so that it was really clean, I might have tried to create a new database linking $uid and $nodeid where $nodeid is the $node of the picture that is the $user's preferred avatar... -- but, well, I still don't know how to set things like that up... and this works too... even if it involves a hack to core...
So, w/o further ado here it is...
Step 1. Modify user.module's function user_validate_picture into what's listed below:
<?php
function user_validate_picture($file, &$edit, $user) {
global $form_values;
// Initialize the picture:
$form_values['picture'] = $user->picture;
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$info = image_get_info($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if (!$info || !$info['extension']) {
form_set_error('picture_upload', t('The uploaded file was not an image.'));
}
else if (image_get_toolkit()) {
/* added */
$maxsize_icon = array('w'=>175,'h'=>175); //clean up
$icon = $file; //file_copy changes the value of the variable
if (file_copy($icon, variable_get('user_picture_path', 'pictures').'/pictureicon-'. $user->uid . '.' . $info['extension'], $replace = FILE_EXISTS_REPLACE)) {
image_scale($icon->filepath, $icon->filepath, $maxsize_icon['w'], $maxsize_icon['h']);
}
$maxsize_mini = array('w'=>20, 'h'=>20);
$mini = $file;
if (file_copy($mini, variable_get('user_picture_path', 'pictures').'/picturemini-'. $user->uid . '.' . $info['extension'], $replace = FILE_EXISTS_REPLACE)) {
image_scale($mini->filepath, $mini->filepath, $maxsize_mini['w'], $maxsize_mini['h']);
}
/* end add */
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
}
else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
if (!form_get_errors()) {
if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid . '.' . $info['extension'], 1)) {
$form_values['picture'] = $file->filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => '<em>'. variable_get('user_picture_path', 'pictures') .'</em>')));
}
}
}
?>
Step 2.
Add this to the end of your template.php file for the template override:
<?phpfunction phptemplate_user_picture($account, $size = '') {
return _phptemplate_callback('user_picture', array('account' => $account, 'size' => $size));
}
?>
Step 3.
Add the file user_picture.tpl.php in your active template folder and put the following into it:
<?php
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
//add these lines in case of icon or mini
if ($size == 'icon') {
$picture = 'files' . variable_get('user_picture_path', 'pictures').'/pictureicon-'. $account->uid . '.jpg';
$picture = file_create_url($picture);
}
else if ($size == 'mini') {
$picture = 'files' . variable_get('user_picture_path', 'pictures').'/picturemini-'. $account->uid . '.jpg';
$picture = file_create_url($picture);
}
else {
$picture = file_create_url($account->picture);
print_r($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', 'Anonymous')));
$picture = theme('image', $picture, $alt, $alt, '', false);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
}
print_r("<div class=\"picture\">$picture</div>");
}
}
?>
Now, anytime you want an userpicture of your preset size, you call the function:
theme('user_picture', $user , $size) ...
For example....
print theme('user_picture',$my_user, 'icon');
Good luck!
Only for 4.7
Albert
www.ithou.org
Patch
I made a patch out of this and added it to http://drupal.org/node/60987. It needs more work, though...
how bout having more images for the user profile?
What do you think would be the best way to get more images on the user profile?
Thanks
Full Module
I think that would have to be done with a full module. Make a request as a new topic, and I bet you'll get a lot of attention.
--
Bradlis7.com | Churchofchristnet
Path gets printed
Hi,
I first tried to install the patch but MAC OSX's terminal claimed it was bad code that ended halfway. Might also have been me being a klutz. Command line is not one of my better features.
However, I used the code posted above instead and now I've got two problems;
1) The user image I'm testing with don't resize when I use $icon or $mini in the user_profile.tpl.php. Am I supposed to determine image sizes anywhere else than in the snippet above or have any other modules installed? I have GD and the image_module installed if that matters.
2) I get the image path written out everywhere the image appears. At a look at the source code it says;
<div class="content">http://quicksilver.local/fixxxa/filer/medlemsbilder/picture-1.gif<div class="picture"><a href="/fixxxa/?q=medlemmar/annika" title="Titta på användarprofilen."><img src="//quicksilver.local/fixxxa/filer/medlemsbilder/picture-1.gif" alt="Annikas bild" title="Annikas bild" /></a></div>The code in the user_profile.tpl.php is
<?phpif($user->picture) {
print theme('user_picture', $user, '$mini');
}
?>
I haven't the faintest idea from where that path comes from. I've redone the process twice to be certain there are no errors, but alas still no success.
I hope somebody can shred some light on this.
Oh, and I'm using Drupal 4.7.2 with a modded Friends Electric theme.
:-)
Ayza
ditto here.. can anybody help?
I am getting the image path written on top of the image too.. can somebody please help?
NetCEO
Same Results
I am also getting the image path, but only on images where I haven't replaced the picture with the new code.
I also don't exactly know how to write it. The example code:
print theme('user_picture',$my_user, 'icon');results in everyone having the default user picture. How do I change '$my_user' to show the picture for that user?
Thanks,
txcrew
Hi everyone, and sorry I'm away for so long...
This is a snippet I wrote a while ago with help from bradlis... and it's kinda receded into the back of my memories... so I'm not sure if this is going to be helpful, but...
Anyhow, these are my best answers:
@Ayza, netceo: I think you need to reupload the pictures, possibly, and then you should get the things to resize? Anyhow, that's the only thing I can think of.
BTW, the other thing is, there is a known bug with *gif* files. For some reason it's not working with gifs, only jpegs... I think... I tried to figure this piece out and maybe I'll get there someday, but I'm kinda swamped right now with trying to get exim set up on my machine.
@txcrew: honestly, i don't remember , but I think $my_user becomes something like the number [or the name? I forget] of the user whose picture you're trying to show.
Good luck everyone!
Albert
www.ithou.org
the giffy thang
Thanx Albert,
I think it's must be the gif bug. I didn't know about it. I'll redo the images in jpeg.
For anyone else reading
For anyone else reading this, the correct thing to replace $my_user with is $node (or $comment for comments).
Regards
Patrick Nelson
www.vcommunity.org.uk
How about a cron job?
Hello all,
I think this mod is a very good idea. I don't understand why drupal doesn't do it by itself yet, or why theres is no module for this.
Either way, I don't like at all to modify drupal's release files because that stops me to upgrade when a new release is available. So I was thinking, what about creating the resized images via cron? It will be a hook which would check if the small images doesn't exist or if the user picture has been updated (date is newer than thumbs), and the create or recreate the small ones.
That way we will have a lag between a picture modification and cron update, but will be way cleaner.
Any ideas of how to implement this? I just don't have time right now, and I would appreciate any code! :)
Sounds like a good idea
Sorry I can't help though. My knowledge about Cron basically stops at knowing how to spell it.
:-)
Ayza
Another way, without modifying Drupal's code.
Based on the code shown above (very good job, ajwwong), I have created what will do the same, but without touching a single line of Drupla's code. This means we don't need to modify user.module file.
The way I have done it, instead of creating thumbnails when user uploads his picture, pictures are resized on demand, if they haven't been resized previously or if user's image has changed.
Step 1: Add this to the end of your template.php (identical to previous 2nd step):
<?phpfunction phptemplate_user_picture($account, $size = '') {
return _phptemplate_callback('user_picture', array('account' => $account, 'size' => $size));
}
?>
Step 2: Add the file user_picture.tpl.php in your active template folder and put the following into it:
<?php
if (variable_get('user_pictures', 0))
{
if ($account->picture && file_exists($account->picture))
{
if ($size == 'node') // 80x80
{
$info = image_get_info($account->picture);
$newpicture = dirname($account->picture) . '/picture-' . $account->uid . ".80." . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
image_scale($account->picture, $newpicture, 80, 80);
}
$picture = file_create_url($newpicture);
}
else if ($size == 'comment') // 48x48
{
$info = image_get_info($account->picture);
$newpicture = dirname($account->picture) . '/picture-' . $account->uid . ".48." . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
image_scale($account->picture, $newpicture, 48, 48);
}
$picture = file_create_url($newpicture);
}
else if ($size == 'mini') // 20x20
{
$info = image_get_info($account->picture);
$newpicture = dirname($account->picture) . '/picture-' . $account->uid . ".20." . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
image_scale($account->picture, $newpicture, 20, 20);
}
$picture = file_create_url($newpicture);
}
else
{
$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', 'Anonymous')));
$picture = theme('image', $picture, $alt, $alt, '', false);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
}
print_r("<div class=\"picture\">$picture</div>");
}
}
?>
Of course the code can be modified for diferent image sizes and even better! It would be very easy to modify it to allow passing the final size in pixels (instead of 'node', comment' and 'mini') and get images at runtime of any size.
I hope you like it! For a demonstration, check out this pages and compare the different picture sizes:
Enjoy!
Wow!
Haven't had a chance to try this out, but this looks like a very elegant solution! I think this should definitely be a candidate for the template snippets handbook.
Congrats, EnekoAlonso!
Albert
www.ithou.org
Thanks for this wonderful
Thanks for this wonderful bit of code.
I'm trying to implement it in my site right now. How exactly do I call it in my theme??
Please let me know when you get a chance.
Thanks,
txcrew
usage of this code
as ajwwong suggested:
<?phpprint theme('user_picture',$my_user, 'icon');
?>
You can put that code in you comment.tpl.php template or in your node.tpl.php template, or instead use it in any php page you create on your site.
Excellent code... !!!
I can confirm that EnekoAlonso's code works, beautifully.
I should say that for some reason, when I chose sizes for my user pictures that were **larger** than what I was actually uploading, e.g., a size of 160x250 when I was only uploading a picture that was 100x120, the script didn't seem to work for the **large** size -- and didn't update the larger picture, even at a smaller sizing. However, I did the following small workaround, as you can see in the example below for the user size 'icon'. YMMV
Additionally, I added some code to make one of the images "square" [and actually slightly centered high].... this is my user size 'tile'.
I'm listing it here for posterity. Good luck all.
[For use in the user_picture.tpl.php file]
<?php
if (variable_get('user_pictures', 0))
{
if ($account->picture && file_exists($account->picture))
{
if ($size == 'icon') // 160x250 This is a BIG user picture
{
$maxsize_icon = array('w'=>160,'h'=>250);
$info = image_get_info($account->picture);
if ($info['height'] < $maxsize_icon['h']) {
$maxsize_icon['h'] = $info['height'];
}
if ($info['width'] < $maxsize_icon['w']) {
$maxsize_icon['w'] = $info['width'];
}
$newpicture = dirname($account->picture) . '/pictureicon-' . $account->uid . '.' . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
image_scale($account->picture, $newpicture, $maxsize_icon['w'], $maxsize_icon['h']);
}
$picture = file_create_url($newpicture);
}
else if ($size == 'tile') // 50x50 -- this is the *old* default size
{
$maxsize_tile = array('w'=>50, 'h'=>50);
$info = image_get_info($account->picture);
$newpicture = dirname($account->picture) . '/picturetile-' . $account->uid . '.' . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
/*Adding this to make the tiles square, but ALSO, centered */
$imageheight = $info['height'];
$imagewidth = $info['width'];
$minside = min($imageheight, $imagewidth);
if ($imageheight > $imagewidth) {
$topleftx = 0;
$toplefty = (($imageheight - $imagewidth)/4);
}
else {
$topleftx = ($imagewidth - $imageheight)/2;
$toplefty = 0;
}
image_crop($account->picture, $newpicture, $topleftx, $toplefty, $minside, $minside);
/*end add ajwwong*/
image_scale($newpicture, $newpicture, $maxsize_tile['w'], $maxsize_tile['h']);
}
$picture = file_create_url($newpicture);
}
else if ($size == 'mini') // 20x20
{
$maxsize_mini = array('w'=>20, 'h'=>20);
$info = image_get_info($account->picture);
$newpicture = dirname($account->picture) . '/picturemini-' . $account->uid . '.' . $info['extension'];
if (!file_exists($newpicture) || (filectime($newpicture) < filectime($account->picture))) {
image_scale($account->picture, $newpicture, $maxsize_mini['w'], $maxsize_mini['h']);
}
$picture = file_create_url($newpicture);
}
else
{
$picture = file_create_url($account