Skip to:
Content
Pages
Categories
Search
Top
Bottom

Avatar Images to grey scale


  • bcanr2d2
    Participant

    @bcanr2d2

    I am trying to use the following code to turn user avatars to greyscale.

    It has never worked, but I am not sure why. I can do it temporarily via CSS, just to show how it will look (that’s not an issue) but would prefer the actual avatars to be greyscale
    Please help

    //Convert to greyscale
    add_filter('xprofile_avatar_uploaded','rb_bw_filter', 10, 2);
    
    function rb_bw_filter($meta) {
    
    //    $path = wp_upload_dir(); // get upload directory
    //    $file = $path['basedir'].'/'.$meta['file']; // Get full size image
    $file =  bp_core_fetch_avatar(array('item_id' => $other_user, 'type' => 'full','html'=>false));
       $files[] = explode(',' ,$file); // Set up an array of image size urls
    //    foreach ($meta['sizes'] as $size) {
    //       $files[] = $path['path'].'/'.$size['file'];
    //    }
    
        foreach ($files as $file) { // iterate through each image size
    
            // Convert image to grayscale credit to http://ottopress.com/2011/customizing-wordpress-images/
    
            list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
            $image = wp_load_image($file);
            imagefilter($image, IMG_FILTER_GRAYSCALE);
            switch ($orig_type) {
                case IMAGETYPE_GIF:
                    imagegif( $image, $file );
                    break;
                case IMAGETYPE_PNG:
                    imagepng( $image, $file );
                    break;
                case IMAGETYPE_JPEG:
                    imagejpeg( $image, $file );
                    break;
            }
        }
        return $meta;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar