src/NuGetGallery/Helpers/GravatarHelper.cs
/// <summary>
/// Generate the HTML to a Gravatar image.
/// </summary>
/// <param name="url">The URL builder.</param>
/// <param name="email">The user's email address.</param>
/// <param name="username">The user's username.</param>
/// <param name="size">The size of the gravatar image.</param>
/// <param name="responsive">If true, the image will scale with its parent element.</param>
/// <returns>The HTML for a Gravatar image.</returns>
Generate the HTML to a Gravatar image.
Generate the HTML to a Gravatar image .
public static HtmlString Image(UrlHelper url, string email, string username, int size, bool responsive)
        {
            var classAttribute = responsive ? "owner-image img-responsive" : "owner-image";
            var imageSize = (size * 2 > 512) ? 512 : size * 2;
            var features = DependencyResolver.Current.GetService<IFeatureFlagService>();
            if (features.IsGravatarProxyEnabled())
            {
                var html = $@"<img src=""{url.Avatar(username, imageSize)}""
                                class=""{classAttribute}""
                                height=""{size}""
                                width=""{size}""
                                title=""{username}""
                                alt=""{username} gravatar"" />";
                return new HtmlString(html);
            }
            if (email == null)
            {
                return new HtmlString(value: null);
            }
            var gravatarHtml = Gravatar.GetHtml(
                email,
                imageSize,
                "retro",
                GravatarRating.G,
                attributes: new
                {
                    width = size,
                    height = size,
                    title = username,
                    @class = classAttribute
                });
            if (gravatarHtml != null && ShouldUseSecureGravatar())
            {
                gravatarHtml = new HtmlString(gravatarHtml.ToHtmlString().Replace(UnsecureGravatarUrl, SecureGravatarUrl));
            }
            return gravatarHtml;
        }
public static HtmlString Image ( UrlHelper url , string email , string username , int size , bool responsive ) { var classAttribute = responsive ? " " : " " ; var imageSize = ( size * 2 > 512 ) ? 512 : size * 2 ; var features = DependencyResolver . Current . GetService < IFeatureFlagService > ( ) ; if ( features . IsGravatarProxyEnabled ( ) ) { var html = $@" <img src= "" { url . Avatar ( username , imageSize ) } "" 
                                class= "" { classAttribute } "" 
                                height= "" { size } "" 
                                width= "" { size } "" 
                                title= "" { username } "" 
                                alt= "" { username }  gravatar ""  /> " ; return new HtmlString ( html ) ; } if ( email == null ) { return new HtmlString ( value : null ) ; } var gravatarHtml = Gravatar . GetHtml ( email , imageSize , " " , GravatarRating . G , attributes : new { width = size , height = size , title = username , @class = classAttribute } ) ; if ( gravatarHtml != null && ShouldUseSecureGravatar ( ) ) { gravatarHtml = new HtmlString ( gravatarHtml . ToHtmlString ( ) . Replace ( UnsecureGravatarUrl , SecureGravatarUrl ) ) ; } return gravatarHtml ; }
Generate the HTML to a Gravatar image.
Generate the HTML to a Gravatar image .
// Load a higher resolution image than the element requires, to improve high DPI display. // However, the maximum allowed Gravatar size is 512 pixels.
The HTML for a Gravatar image.
The HTML for a Gravatar image .
url
UrlHelper
The URL builder.
The URL builder .
email
string
The user's email address.
The user ' s email address .
username
string
The user's username.
The user ' s username .
size
int
The size of the gravatar image.
The size of the gravatar image .
responsive
bool
If true, the image will scale with its parent element.
If true the image will scale with its parent element .