Ejemplo n.º 1
0
        ///  <summary>
        ///  Compose a valid Gravatar Url from email
        ///
        ///   see : https://gravatar.com/site/implement/images/
        ///   for more details
        ///  </summary>
        ///  <param name="mailAdd">Address to use</param>
        ///  <param name="size">By default, images are presented at 80px by 80px</param>
        ///  <param name="default">
        ///     404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
        ///     mm: (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
        ///     identicon: a geometric pattern based on an email hash
        ///     monsterid: a generated 'monster' with different colors, faces, etc
        ///     wavatar: generated faces with differing features and backgrounds
        ///      retro: awesome generated, 8-bit arcade-style pixelated faces
        ///     blank: a transparent PNG image (border added to HTML below for demonstration purposes)
        /// </param>
        /// <param name="altText">Alternate text for image (default : Gravatar Image)</param>
        /// <returns>url of Gravatar image</returns>
        public static string CreateGravatarUrl(string mailAdd,
                                               int size = 80, string @default = "404", string altText = "Gravatar Image")
        {
            const string gravatarUrl = "<img src='http://www.gravatar.com/avatar/{0}?s={1}&d={2}'  alt='{3}'>";
            var          hash        = (string.IsNullOrWhiteSpace(mailAdd)) ? "unknow" : MD5Helpers.GetMd5Hash(mailAdd);

            return(string.Format(gravatarUrl, hash, size, @default, altText));
        }
Ejemplo n.º 2
0
        ///  <summary>
        ///  Compose a valid Gravatar Url from email
        ///
        ///   see : https://fr.gravatar.com/site/implement/images/
        ///   for more details
        ///  </summary>
        ///  <param name="helper">Html Helper context</param>
        ///  <param name="mailAdd">Address to use</param>
        ///  <param name="size">By default, images are presented at 80px by 80px</param>
        ///  <param name="default">
        ///     404: do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
        ///     mm: (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
        ///     identicon: a geometric pattern based on an email hash
        ///     monsterid: a generated 'monster' with different colors, faces, etc
        ///     wavatar: generated faces with differing features and backgrounds
        ///      retro: awesome generated, 8-bit arcade-style pixelated faces
        ///     blank: a transparent PNG image (border added to HTML below for demonstration purposes)
        /// </param>
        /// <param name="altText">Alternate text for image (default : Gravatar Image)</param>
        /// <param name="cssClass">Add a special class on img tag</param>
        /// <returns>url of Gravatar image</returns>
        public static MvcHtmlString GravatarImage(this HtmlHelper helper, string mailAdd,
                                                  int size = 80, string @default = "404", string cssClass = "", string altText = "Gravatar Image")
        {
            const string gravatarUrl = "<img src='http://www.gravatar.com/avatar/{0}?s={1}&d={2}' {4} alt='{3}'>";
            var          hash        = (string.IsNullOrWhiteSpace(mailAdd)) ? "unknow" : MD5Helpers.GetMd5Hash(mailAdd);

            if (cssClass != "")
            {
                cssClass = "class='" + cssClass + "'";
            }

            return(new MvcHtmlString(string.Format(gravatarUrl, hash, size, @default, altText, cssClass)));
        }