Guestbook avatar size settings

atuyo60 - August 5, 2008 - 10:38
Project:Guestbook
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

Sorry I do not have a patch program, but this just requires a small edit which would let admins choose a thumbnail size for avatars in the guestbook. In the theme_guestbook_user_picture() function AFTER the following code:

if (variable_get('user_pictures', 0)) {
    if ($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', '');
    }

ADD:

    $thumbnail = variable_get('guestbook_thumbnail', 40);
    $size = image_get_info($picture);
    if ($size['width'] != 0)
      $check = ($thumbnail / $size['width']) * $size['height'];

    if ($check > $thumbnail) {
      $attributes = array("height" => $thumbnail);
    }
    else {
      $attributes = array("width" => $thumbnail);
    }
    unset($thumbnail, $size, $check); // Destroy variables

Then ADD the $attributes array to the theme_image, edit to this:

if (isset($picture)) {
      $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', 'Anonymous')));
      $picture = theme('image', $picture, $alt, $alt, $attributes, FALSE);

For admins to set the size, ADD to guestbook_admin_settings():

$form['display_options']['guestbook_thumbnail'] = array(
    '#type' => 'textfield',
    '#title' => t('Thumbnail size'),
    '#default_value' => variable_get('guestbook_thumbnail', 40),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Size of user avatars within the guestbook.'),
  );

#1

sun - August 6, 2008 - 15:19
Status:active» won't fix

This won't fix. Beginning from version 2.x, Guestbook will implement support for User Display API, which allows very fine grained control over the output of users.

#2

atuyo60 - August 6, 2008 - 16:13
Status:won't fix» closed

Hi, what do you mean by it won't fix? Is it another way of saying it won't be implemented?

Anyway its just a suggestion, and I am not a fan of installing another module just to implement such a small issue. I used to have imagecache installed but its memory usage was too much for my purpose. I do not have the freedom of a VPS or dedicated server so for me the lesser modules the better.

#3

sun - August 6, 2008 - 16:32
Status:closed» won't fix

Won't fix means that this feature will not be implemented (or if it was a bug report, the bug cannot be fixed). Issues marked as won't fix do not need to be closed. Instead, leaving the issue on its state provides a little extra information for other users stumbling over this issue.

By implementing User Display API, we can probably eliminate 10-20% of the code in Guestbook, maybe even more. So by implementing that API (and thus, requiring another module), we can add more possibilities by actually reducing the memory footprint for Drupal + Guestbook. Also, beginning from 2.x, the module will be separated into multiple module files, which adds to the aforementioned goal.

#4

atuyo60 - August 6, 2008 - 18:06

mm.. thanks for explaining, I will weigh my options when the new version is out, and thanks for your work on this module!

#5

etcetera9 - July 28, 2009 - 11:09

When I was waiting for the 2.x release, I used the above approach and it just works fine. Before that I tried imagecache_profiles with some tweaks but couldnt manage it. Thank you for sharing...

Cheers,

Sinan

#6

GetLives - July 28, 2009 - 19:27

It's easy to change the code yourself and add imagecache support.

#7

etcetera9 - July 28, 2009 - 22:02

How? I found it difficult...

#8

a.luiz.n - August 18, 2009 - 13:33

i'm trying to do this with this function:

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

this function get a piece of the string between two other strings.

in the user object i have $account->field_user_avatar which is a link to the image of the user in the imagecache path.
so i have to pick only the name of the picture.
so i discovered the path and make it static. "/sites/default/files/imagecache/Avatar_thumb/avatar/"

then i have to add the name of the picture...

$imgname = get_string_between($end, "avatar/", "*");

but the * is something i dont have yet...i have to set a caracter to be the end.

#9

a.luiz.n - September 8, 2009 - 20:49

with the help of the above function i created my own function to return the user picture (imagecache)

function mytheme_user_picture($uid) {
  if ($uid != 0) {
    $profile = content_profile_load('profile', $uid);
    $imgpath = $profile->field_user_avatar[0]['filepath'] . '!'; //add ! to the end of the path so that i can set the end to the function get_string_between
    $imgname = get_string_between($imgpath, 'avatar/', '!'); //get the name of the file
 
    return '<img src="/sites/default/files/imagecache/Avatar_thumb/avatar/' . $imgname . '" alt="' . $profile->title . '" />';
  }
}

where profile is the name of the content node type
/sites/default/files/imagecache/Avatar_thumb/avatar/ is the static path of my pictures

now i need to implement the default image

#10

a.luiz.n - September 8, 2009 - 21:08

just add this

if ($profile->field_user_avatar[0]['filepath']) {
  $dir = 'avatar/';
  $imgpath = $profile->field_user_avatar[0]['filepath'] . '!';
  $imgname = get_string_between($imgpath, 'avatar/', '!');
}
else {
  $dir = 'imagefield_default_images/';
  $imgname = 'user.png'; //the name of the default pic
}

 
 

Drupal is a registered trademark of Dries Buytaert.