public static string GetGravatar(string email, ProfileImageSize imageSize) { using (MD5 md5Hash = MD5.Create()) { return string.Format("http://www.gravatar.com/avatar/{0}?s={1}&d=mm", GetMd5Hash(md5Hash, email), (int)imageSize); } }
public static void RemoveUserProfileImage(int userId, ProfileImageSize profileImageSize) { var image = GetUserProfileImagePath(userId, profileImageSize); if (File.Exists(image)) { File.Delete(image); } }
public static string GetUserProfileImagePath(int userId, ProfileImageSize profileImageSize, string fileExtensionsToSearch = "jpeg,png") { string path; if (TryGetUserProfileImagePath(userId, profileImageSize, out path, fileExtensionsToSearch)) { return(path); } throw new FileNotFoundException(); }
public static string FormatProfileImagePath(ProfileImageSize profileImageSize, int imageId, string imageBaseUrl) { switch (profileImageSize) { case ProfileImageSize.Normal: return(imageBaseUrl + "profile/normal/" + MagicStrings.FILE_PROFILEIMAGE_PREFIX + imageId + ".png"); case ProfileImageSize.Tiny: return(imageBaseUrl + "profile/tiny/" + MagicStrings.FILE_PROFILEIMAGE_PREFIX + imageId + ".png"); default: throw new NotImplementedException(); } }
public bool TryGetProfileImageFilePath(int userId, ProfileImageSize profileImageSize, out string path, out string fileMime) { var userHasProfileImage = HasUserProfileImage(userId); if (userHasProfileImage) { path = AppFileManager.GetUserProfileImagePath(userId, profileImageSize); fileMime = MimeHelper.GetMime(Path.GetExtension(path)); return(true); } path = null; fileMime = null; return(false); }
public static bool TryGetUserProfileImagePath(int userId, ProfileImageSize profileImageSize, out string userProfileImagePath, string fileExtensionsToSearch = "jpeg,png") { var extensions = fileExtensionsToSearch.Split(','); foreach (var ext in extensions) { var path = $"{AppDirectoryManager.GetUserProfileImageDirectory(userId)}\\{profileImageSize.ToString()}.{ext}"; if (File.Exists(path)) { userProfileImagePath = path; return(true); } } userProfileImagePath = null; return(false); }
/// <summary> /// Access the profile image in various sizes for the user with the indicated screenName. /// If no size is provided the normal image is returned. /// </summary> /// <param name="screenName"></param> /// <param name="profileImageSize"></param> /// <returns></returns> /// <remarks> /// This method should only be used by application developers to lookup or check the profile image URL /// for a user. This method must not be used as the image source URL presented to users of your application. /// </remarks> public Uri RetrieveProfileImageUri(string screenName, ProfileImageSize profileImageSize = ProfileImageSize.Normal) { if (String.IsNullOrEmpty(screenName)) { throw new ArgumentException(); } var uri = new Uri(this.CommandBaseUri + String.Format("/profile_image/{0}.json?size={1}", screenName, profileImageSize.ToString().ToLowerInvariant())); var response = this.TwitterApi.ExecuteUnauthenticatedRequest(uri); var pattern = @"(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*"; var match = Regex.Match(response, pattern); if (!match.Success) { throw new TwitterException("Unrecognized response.\n Server Response: \n" + response); } return(new Uri(match.Value)); }
public static string GetAnonymousUserIconPhysicalPath(ProfileImageSize profileImageSize) { string fileName; switch (profileImageSize) { case ProfileImageSize.Large: fileName = "user_300x300.png"; break; case ProfileImageSize.Medium: fileName = "user_80x80.png"; break; case ProfileImageSize.Small: fileName = "user_40x40.png"; break; default: fileName = "user_40x40.png"; break; } return(HttpContext.Current.Server.MapPath($"~/content/assets/global/img/user/{fileName}")); }
public static string CalculateUserProfileImagePath(int userId, ProfileImageSize profileImageSize, string fileExtension) { return($"{AppConfigurationManager.AppDirectory}\\Users\\{userId}\\ProfileImage\\{profileImageSize.ToString()}{fileExtension}"); }
public static HtmlString LinkedImage(string action, string controller, string id, string userName, string email, ProfileImageSize imageSize) { return new HtmlString(string.Format("<a href='/{0}/{1}/{2}'><img src='{3}' alt='{4}' title='{4}' class='img-polaroid' /></a>", controller, id, GenerateSlug(userName), GetGravatar(email, imageSize), userName)); }