Changeset 671
- Timestamp:
- 09/09/07 16:57:42 (1 year ago)
- Files:
-
- avatar-upload/trunk/additional-files/avatar-upload.php (modified) (5 diffs)
- avatar-upload/trunk/additional-files/my-templates/avatar.php (modified) (1 diff)
- avatar-upload/trunk/bb-avatar-upload.php (modified) (4 diffs)
- avatar-upload/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
avatar-upload/trunk/additional-files/avatar-upload.php
r531 r671 34 34 if (!empty($_FILES['p_browse'])) 35 35 { 36 $current_avatar = avatarupload_get_avatar($user_id, 0, 1); // for comparison later 36 $arr_current_avatar = avatarupload_get_avatar($user_id, 0, 1); 37 $current_avatar = ereg_replace("\?[0-9]+$", "", $arr_current_avatar[0]); // for comparison later 37 38 38 39 // Grab the uploaded image … … 82 83 $img_size = @filesize($img_temp); 83 84 list($img_w, $img_h) = $resized; // overwrite image width / height 85 86 87 // Do we want a thumbnail and was it successful? 88 if ($config->use_thumbnail == 1) 89 { 90 $thumb_file = BBPATH . $config->avatar_dir . "thumb." . $user_filename; 91 92 if ( !$thumbresized = avatar_thumbnail($img_temp, $img_w, $img_h, $img_type, $thumb_file) ) 93 { 94 $img_errs = 12; 95 } 96 } 97 84 98 } 85 99 } … … 101 115 { 102 116 // Compare 'new' and 'current' avatar filenames 103 if (!empty($current_avatar [0]) && $user_filename != $current_avatar[0])117 if (!empty($current_avatar) && $user_filename != $current_avatar) 104 118 { 105 119 // If different, delete 'current' - this will only occur when 106 120 // the new and current avatars have different file extensions. 107 @unlink(BBPATH . $config->avatar_dir . $current_avatar[0]); 121 @unlink(BBPATH . $config->avatar_dir . $current_avatar); 122 @unlink(BBPATH . $config->avatar_dir . "thumb." . $current_avatar); 108 123 } 109 124 … … 150 165 case 11: // custom error code 151 166 $error_message = __("The file could not be saved to the {$config->avatar_dir} folder."); 167 break; 168 case 12: // custom error code 169 $error_message = __("The thumbnail file could not be saved to the {$config->avatar_dir} folder."); 152 170 break; 153 171 default: // unknown error (this probably won't ever happen) … … 261 279 } 262 280 281 282 /* Image thumbnail */ 283 function avatar_thumbnail($img_temp, $img_w, $img_h, $img_type, $img_thumb_name) 284 { 285 global $config; 286 287 // if either the image width or height is greater than the maximums allowed 288 if ($img_w > $config->thumb_width || $img_h > $config->thumb_height) 289 { 290 // To maintain aspect ratio we need to resize proportionally 291 292 if ($img_w > $img_h) 293 { 294 // width is greater - make width 'max_width' and proportion height 295 $new_width = $config->thumb_width; 296 $new_height = round($img_h * ($config->thumb_width/$img_w)); 297 } 298 else if ($img_w < $img_h) 299 { 300 // height is greater - make height 'max_height' and proportion width 301 $new_width = round($img_w * ($config->thumb_height/$img_h)); 302 $new_height = $config->thumb_height; 303 } 304 else 305 { 306 // equal (square) - make both 'max' values 307 $new_width = $config->thumb_width; 308 $new_height = $config->thumb_height; 309 } 310 } 311 else 312 { 313 // image already within maximum limits - do not resize 314 $new_width = $img_w; 315 $new_height = $img_h; 316 } 317 318 // Thumbnail coordinates if width/height smaller than max thumb size 319 // because we want a square thumb image. 320 $x_start = ($config->thumb_width - $new_width > 0) ? round(($config->thumb_width - $new_width)/2) : 0; 321 $y_start = ($config->thumb_height - $new_height > 0) ? round(($config->thumb_height - $new_height)/2) : 0; 322 323 // Can we use a truecolor image? 324 $truecolor = function_exists('imagecreatetruecolor'); 325 326 // Resize the image, preserving image type 327 328 switch ($img_type) 329 { 330 case 1: 331 // GIF 332 $im1 = @imagecreatefromgif($img_temp); 333 $im2 = @imagecreate($config->thumb_width, $config->thumb_height) or $error = 1; 334 $bg = @imagecolorallocate($im2, 192, 192, 192); // default background color 335 @imagecolortransparent($im2, $bg); // make it transparent 336 @imagecopyresampled ($im2, $im1, $x_start, $y_start, 0, 0, $new_width, $new_height, $img_w, $img_h); 337 @imagegif($im2, $img_thumb_name); 338 break; 339 340 case 2: 341 // JPEG 342 $im1 = @imagecreatefromjpeg($img_temp); 343 $im2 = ($truecolor) ? @imagecreatetruecolor($config->thumb_width, $config->thumb_height) : @imagecreate($config->thumb_width, $config->thumb_height); 344 @imagecopyresampled ($im2, $im1, $x_start, $y_start, 0, 0, $new_width, $new_height, $img_w, $img_h); 345 $im2 = ($truecolor) ? do_unsharp_mask($im2, $config->use_unsharpmask) : $im2; 346 @imagejpeg($im2, $img_thumb_name, 100); // quality integer might become config variable 347 break; 348 349 case 3: 350 // PNG 351 $im1 = @imagecreatefrompng($img_temp); 352 $im2 = ($truecolor) ? @imagecreatetruecolor($config->thumb_width, $config->thumb_height) : @imagecreate($config->thumb_width, $config->thumb_height); 353 $bg = @imagecolorallocate($im2, 192, 192, 192); // default background colour 354 @imagecolortransparent($im2, $bg); // make it transparent 355 @imagealphablending($im2, false); // stop alpha blending 356 @imagesavealpha($im2, true); // save original image alpha channel 357 @imagecopyresampled ($im2, $im1, $x_start, $y_start, 0, 0, $new_width, $new_height, $img_w, $img_h); 358 $im2 = ($truecolor) ? do_unsharp_mask($im2, $config->use_unsharpmask) : $im2; 359 @imagepng($im2, $img_thumb_name); 360 break; 361 362 default: 363 $error = 1; 364 break; 365 } 366 367 @imagedestroy($im2); 368 @imagedestroy($im1); 369 370 if ($error > 0) 371 { 372 // Something went wrong. 373 return false; 374 } else { 375 // return the new sizes 376 return array($new_width, $new_height); 377 } 378 } 379 263 380 ?> avatar-upload/trunk/additional-files/my-templates/avatar.php
r532 r671 29 29 <h3><?php _e('Current Avatar'); ?></h3> 30 30 31 <p><?php echo avatarupload_display($user->ID, $force_db); ?></p> 31 <p><?php 32 echo avatarupload_display($user->ID, $force_db); 33 34 if ($config->use_thumbnail == 1) { 35 echo " " . avatarupload_displaythumb($user->ID, $force_db) . "</p>"; 36 } 37 ?></p> 32 38 33 39 <?php if (!usingidenticon($user->ID)) { ?> avatar-upload/trunk/bb-avatar-upload.php
r568 r671 3 3 Plugin Name: Avatar Upload 4 4 Plugin URI: http://bbpress.org/plugins/topic/46 5 Version: 0.8. 25 Version: 0.8.3 6 6 Description: Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. 7 7 Author: Louise Dade … … 51 51 $this->use_unsharpmask = 1; 52 52 53 // Use a thumbnail image (hidden feature for now). 1 = yes / 0 = no (default) 54 $this->use_thumbnail = 0; 55 $this->thumb_width = 25; 56 $this->thumb_height = 25; 57 53 58 // Default avatar - set 'use_default' to '0' to display Identicon instead of default 54 59 // The default URI is in the '$this->avatar_dir' folder. … … 102 107 } 103 108 109 // Display the avatar image 110 function avatarupload_displaythumb($id, $force_db=0, $class='avatar_thumb') 111 { 112 $config = new avatarupload_config(); 113 114 if ($a = avatarupload_get_avatar($id,1,$force_db, 1)) 115 { 116 echo '<img src="'.$a[0].'" width="'.$config->thumb_width.'" height="'.$config->thumb_height.'" alt="'.$a[4].'" class="'.$class.'" />'; 117 } 118 } 119 104 120 // Get the avatar URI ($id = user->ID, $fulluri = full url to image, 105 121 // $force_db = get avatar from database where 'usermeta' not already available) 106 function avatarupload_get_avatar($id, $fulluri=1, $force_db=0 )122 function avatarupload_get_avatar($id, $fulluri=1, $force_db=0, $is_thumb=0) 107 123 { 108 124 global $bbdb, $user; … … 132 148 return false; 133 149 } 150 } 151 152 if ($is_thumb == 1) 153 { 154 $a[0] = "thumb.".$a[0]; 134 155 } 135 156 avatar-upload/trunk/readme.txt
r568 r671 4 4 Requires at least: 0.8.2 5 5 Tested up to: 0.8.2.1 6 Stable Tag: 0.8. 26 Stable Tag: 0.8.3 7 7 8 8 Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. Admins can configure maximum allowed file size and image dimensions. Includes fel64's code enabling 'Identicons' - default avatars made of abstract patterns unique to each user.
