• Resolved Luke

    (@lukejanicke)


    I just noticed gravatars on my site aren’t getting the @2x treatment. All other images are properly getting the @2x suffix to the source URL. I’m using the PHP provided by gravatar.

    This is easy to work around for now, since my use case is author profile pictures at 20px square. I can call 40px gravatars and force them to 20px with CSS.

    Here’s my code for reference.

    function roots_theme_get_author_gravatar( $ID = '' ) {
    
    	// Get Author Gravatar
    
    	if ( !$ID ) $ID = get_the_author_meta( 'ID' );
    	$name   = get_the_author_meta( 'display_name', $ID );
    	$email  = get_the_author_meta( 'user_email', $ID );
    	$size   = 20;
    
    //	$source = roots_theme_get_gravatar( $email, $size );
    //	return sprintf( '<img src="%s" alt="%s">', $source, $name );
    
    	return roots_theme_get_gravatar( $email, $size, 'mm', 'g', true );
    
    }
    
    /**
     * Get either a Gravatar URL or complete image tag for a specified email address.
     *
     * @param string $email The email address
     * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
     * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
     * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
     * @param boole $img True to return a complete IMG tag False for just the URL
     * @param array $atts Optional, additional key/value attributes to include in the IMG tag
     * @return String containing either just a URL or a complete image tag
     * @source https://gravatar.com/site/implement/images/php/
     */
    function roots_theme_get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
    	$return = 'https://www.gravatar.com/avatar/';
    	$return .= md5( strtolower( trim( $email ) ) );
    	$return .= "?s=$s&d=$d&r=$r";
    	if ( $img ) {
    		$return = '<img src="' . $return . '"';
    		foreach ( $atts as $key => $val )
    			$return .= ' ' . $key . '="' . $val . '"';
    		$return .= ' />';
    	}
    	return $return;
    }

    https://www.ads-software.com/plugins/wp-retina-2x/

Viewing 1 replies (of 1 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Hi Luke,

    I am doing the same for my websites, I am always getting a doubled version of the image I really need. There is no way to handle retina with Gravatar unfortunately since the images are hosted on a different service.

    Thanks for sharing your code, it will be helpful for others ??

Viewing 1 replies (of 1 total)
  • The topic ‘Gravatars @2x’ is closed to new replies.