Announcement

Collapse
No announcement yet.

Avatar size

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Avatar size

    Hi Glenn,

    I have changed the max avatar size in /core/includes/class_core.php, used additional css and changed usergroup settings to change the default avatar size to 150 x 150 pixels. When a member changes his avatar, it is displayed as 150 x 150 in his profile, but as 100 x 100 in threads. When I move the avatars from the file system to the database and back, they are displayed correctly.

    What can I do to fix this issue? Is there are scheduled task I can run?

    Thanks,
    Rob

    #2
    Try running AdminCP > Maintenance > General Update Tools > Rebuild Custom Avatar Thumbnails

    Comment


      #3
      I get the message that the custom avatar thumbnail directory is not writable, which is strange because I am certain that it is.

      Comment


      • glennrocksvb
        glennrocksvb commented
        Editing a comment
        Are you looking at the correct directory?

      • Fleiding
        Fleiding commented
        Editing a comment
        /core/customavatars

      #4
      I still haven't figured out the issue that when members upload a new 150 x 150 avatar, it get's displayed as a 100 x 100 avatar. When I move the avatars from the file system to the database and back, they are displayed at 150 x 150.

      I use the following custom CSS:
      Code:
      .l-desktop .b-avatar--m > img {
          max-height: 150px;
          max-width: 150px !important;
      }
      .l-desktop .b-avatar--m {
          height: 100%;
          width: 100%;
      }
      Is there a way to fix this? Please note that some members are using avatars of 100 x 100, 80 x 80 and other sizes, so they should not be enlarged to 150 x 150.

      Comment


        #5
        Originally posted by Fleiding View Post
        when members upload a new 150 x 150 avatar, it get's displayed as a 100 x 100 avatar. When I move the avatars from the file system to the database and back, they are displayed at 150 x 150.
        Is this issue consistently happening? When does it happen, when members upload an avatar for the first time?

        Comment


          #6
          It's consistently happening, not only when members upload a avatar for the first time.

          Comment


            #7
            Do you know if there is a cron job I can run which moves avatars to the database and then back to the file system every 24 hours or so?

            Comment


              #8
              Uhh yess, those little avatars are my first mission too.

              Comment


                #9
                I no this is a older thread but i have the same problem and im positive its set to 777

                Comment


                  #10
                  Change the folder.. move it somewhere else... sometimes it works. The Update Avatars thingy is sooooooo buggy

                  Comment


                    #11
                    So after some digging in... the actual code in vBulletin is:

                    PHP Code:
                    if ($vbulletin->options['usefileavatar'] AND !is_writable($vbulletin->options['avatarpath'])) 
                    But somehow vBulletin ALWAYS seems to be confused whether the avatars are actually inside the DB or just filesystem... the actual PHP is_writable function... is functioning correctly.

                    In any event, to actually resize the avatars (once you've set a custom size in the defines) the "Rebuild" does.... NOTHING. Well not for me.

                    I've written a script to go through all of them and correctly resize per my liking. I can share if anyone is interested.

                    Comment


                    • Papa Bear
                      Papa Bear commented
                      Editing a comment
                      yes please share..

                    #12
                    Ok, here goes...

                    First file: updateavatars.php - upload it somewhere on your server, and update the DB connection info and file paths as needed as well as the image size.

                    PHP Code:
                    <?php
                    ini_set
                    ("include_path"'/home/xxx/path/toforum:' ini_get("include_path") );
                    include(
                    "resize_class.php");

                    if (!isset(
                    $_REQUEST['startAt']))
                    $startAt 0;
                    else
                    $startAt $_REQUEST['startAt'];

                    $perPage 30;

                    /* DataBase Settings */
                    $HostnameBD 'localhost';
                    $UserBD 'xxx';
                    $PassBD 'xxx';
                    $NameBD 'xxx';
                    $conexiune = @mysqli_connect($HostnameBD,$UserBD,$PassBD) or die(mysql_error());
                    @
                    mysqli_select_db($conexiune,$NameBD) or die(mysql_error());
                    @
                    mysqli_set_charset($conexiune,'UTF8');

                    $avatarPath './customavatars/';

                    clearstatcache();
                    if (!
                    is_writable($avatarPath))
                    {
                    die(
                    'custom_avatarpath_not_writable');
                    }

                    $query "SELECT user.userid, user.avatarrevision, customavatar.filedata, customavatar.filename, customavatar.dateline, customavatar.width, customavatar.height FROM customavatar AS customavatar INNER JOIN user AS user ON(user.userid=customavatar.userid) WHERE customavatar.userid >= ".$startAt." ORDER BY customavatar.userid LIMIT ".$perPage.";";
                    $result mysqli_query($conexiune,$query);
                    if (
                    $result && mysqli_num_rows($result) > 0) {
                    while (
                    $currentRow mysqli_fetch_assoc($result)) {
                    echo 
                    $avatarPath.$currentRow['filename'].' -> '.$avatarPath.'thumbs/'.$currentRow['filename'];
                    // *** 1) Initialise / load image
                    $resizeObj = new resize($avatarPath.$currentRow['filename']);
                    // *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
                    $resizeObj -> resizeImage(124124'crop');
                    // *** 3) Save image
                    unlink($avatarPath.'thumbs/'.$currentRow['filename']);
                    $resizeObj -> saveImage($avatarPath.'thumbs/'.$currentRow['filename'], 93);
                    $startAt $currentRow['userid'];
                    echo 
                    '<hr/>';
                    }

                    }
                    else
                    die(
                    "Error SQL");

                    echo 
                    '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=https://www.xxx.ro/xxx/updateavatars.php?startAt='.$startAt.'">';
                    Second file: resize_class.php

                    PHP Code:
                    <?php

                    # ================================================== ======================#
                    # Requires : Requires PHP5, GD library.
                    # Usage Example:
                    # include("resize_class.php");
                    # $resizeObj = new resize('images/cars/large/input.jpg');
                    # $resizeObj -> resizeImage(150, 100, 0);
                    # $resizeObj -> saveImage('images/cars/large/output.jpg', 100);
                    # ================================================== ======================#


                    class resize
                    {
                    // *** Class variables
                    private $image;
                    private 
                    $width;
                    private 
                    $height;
                    private 
                    $imageResized;

                    function 
                    __construct($fileName)
                    {
                    // *** Open up the file
                    $this->image $this->openImage($fileName);

                    // *** Get width and height
                    $this->width = @imagesx($this->image);
                    $this->height = @imagesy($this->image);
                    }

                    ## --------------------------------------------------------

                    private function openImage($file)
                    {
                    // *** Get extension
                    $extension strtolower(strrchr($file'.'));
                    $img imagecreatefromstring(file_get_contents($file));
                    /*switch($extension)
                    {
                    case '.jpg':
                    case '.jpeg':
                    $img = imagecreatefromjpeg($file);
                    break;
                    case '.gif':
                    $img = imagecreatefromgif($file);
                    break;
                    case '.png':
                    $img = imagecreatefrompng($file);
                    break;
                    default:
                    $img = false;
                    break;
                    }*/
                    return $img;
                    }

                    ## --------------------------------------------------------

                    public function resizeImage($newWidth$newHeight$option="auto")
                    {
                    // *** Get optimal width and height - based on $option
                    $optionArray $this->getDimensions($newWidth$newHeight$option);

                    $optimalWidth $optionArray['optimalWidth'];
                    $optimalHeight $optionArray['optimalHeight'];


                    // *** Resample - create image canvas of x, y size
                    $this->imageResized imagecreatetruecolor($optimalWidth$optimalHeight);
                    imagecopyresampled($this->imageResized$this->image0000$optimalWidth$optimalHeight$this->width$this->height);


                    // *** if option is 'crop', then crop too
                    if ($option == 'crop') {
                    $this->crop($optimalWidth$optimalHeight$newWidth$newHeight);
                    }
                    }

                    ## --------------------------------------------------------

                    private function getDimensions($newWidth$newHeight$option)
                    {

                    switch (
                    $option)
                    {
                    case 
                    'exact':
                    $optimalWidth $newWidth;
                    $optimalHeight$newHeight;
                    break;
                    case 
                    'portrait':
                    $optimalWidth $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight$newHeight;
                    break;
                    case 
                    'landscape':
                    $optimalWidth $newWidth;
                    $optimalHeight$this->getSizeByFixedWidth($newWidth);
                    break;
                    case 
                    'auto':
                    $optionArray $this->getSizeByAuto($newWidth$newHeight);
                    $optimalWidth $optionArray['optimalWidth'];
                    $optimalHeight $optionArray['optimalHeight'];
                    break;
                    case 
                    'crop':
                    $optionArray $this->getOptimalCrop($newWidth$newHeight);
                    $optimalWidth $optionArray['optimalWidth'];
                    $optimalHeight $optionArray['optimalHeight'];
                    break;
                    }
                    return array(
                    'optimalWidth' => $optimalWidth'optimalHeight' => $optimalHeight);
                    }

                    ## --------------------------------------------------------

                    private function getSizeByFixedHeight($newHeight)
                    {
                    $ratio $this->width $this->height;
                    $newWidth $newHeight $ratio;
                    return 
                    $newWidth;
                    }

                    private function 
                    getSizeByFixedWidth($newWidth)
                    {
                    $ratio $this->height $this->width;
                    $newHeight $newWidth $ratio;
                    return 
                    $newHeight;
                    }

                    private function 
                    getSizeByAuto($newWidth$newHeight)
                    {
                    if (
                    $this->height $this->width)
                    // *** Image to be resized is wider (landscape)
                    {
                    $optimalWidth $newWidth;
                    $optimalHeight$this->getSizeByFixedWidth($newWidth);
                    }
                    elseif (
                    $this->height $this->width)
                    // *** Image to be resized is taller (portrait)
                    {
                    $optimalWidth $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight$newHeight;
                    }
                    else
                    // *** Image to be resizerd is a square
                    {
                    if (
                    $newHeight $newWidth) {
                    $optimalWidth $newWidth;
                    $optimalHeight$this->getSizeByFixedWidth($newWidth);
                    } else if (
                    $newHeight $newWidth) {
                    $optimalWidth $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight$newHeight;
                    } else {
                    // *** Sqaure being resized to a square
                    $optimalWidth $newWidth;
                    $optimalHeight$newHeight;
                    }
                    }

                    return array(
                    'optimalWidth' => $optimalWidth'optimalHeight' => $optimalHeight);
                    }

                    ## --------------------------------------------------------

                    private function getOptimalCrop($newWidth$newHeight)
                    {

                    $heightRatio $this->height $newHeight;
                    $widthRatio $this->width $newWidth;

                    if (
                    $heightRatio $widthRatio) {
                    $optimalRatio $heightRatio;
                    } else {
                    $optimalRatio $widthRatio;
                    }

                    $optimalHeight $this->height $optimalRatio;
                    $optimalWidth $this->width $optimalRatio;

                    return array(
                    'optimalWidth' => $optimalWidth'optimalHeight' => $optimalHeight);
                    }

                    ## --------------------------------------------------------

                    private function crop($optimalWidth$optimalHeight$newWidth$newHeight)
                    {
                    // *** Find center - this will be used for the crop
                    $cropStartX = ( $optimalWidth 2) - ( $newWidth /);
                    $cropStartY = ( $optimalHeight2) - ( $newHeight/);

                    $crop $this->imageResized;
                    //imagedestroy($this->imageResized);

                    // *** Now crop from center to exact requested size
                    $this->imageResized imagecreatetruecolor($newWidth $newHeight);
                    imagecopyresampled($this->imageResized$crop 00$cropStartX$cropStartY$newWidth$newHeight $newWidth$newHeight);
                    }

                    ## --------------------------------------------------------

                    public function saveImage($savePath$imageQuality="100")
                    {
                    // *** Get extension
                    $extension strrchr($savePath'.');
                    $extension strtolower($extension);

                    switch(
                    $extension)
                    {
                    case 
                    '.jpg':
                    case 
                    '.jpeg':
                    if (
                    imagetypes() & IMG_JPG) {
                    imagejpeg($this->imageResized$savePath$imageQuality);
                    }
                    break;

                    case 
                    '.gif':
                    if (
                    imagetypes() & IMG_GIF) {
                    imagegif($this->imageResized$savePath);
                    }
                    break;

                    case 
                    '.png':
                    // *** Scale quality from 0-100 to 0-9
                    $scaleQuality round(($imageQuality/100) * 9);

                    // *** Invert quality setting as 0 is best, not 9
                    $invertScaleQuality $scaleQuality;

                    if (
                    imagetypes() & IMG_PNG) {
                    imagepng($this->imageResized$savePath$invertScaleQuality);
                    }
                    break;

                    // ... etc

                    default:
                    // *** No extension - No save.
                    break;
                    }

                    imagedestroy($this->imageResized);
                    }


                    ## --------------------------------------------------------

                    }
                    ?>

                    Comment


                    • Papa Bear
                      Papa Bear commented
                      Editing a comment
                      very cool thanks..
                  Working...
                  X