public void CropUserProfileImages(int userId, ProfileImageCropInfoPM cropInfo) { var originalImagePath = AppFileManager.GetUserProfileImagePath(userId, ProfileImageSize.Original); var extension = Path.GetExtension(originalImagePath); var largeImagePath = AppFileManager.CalculateUserProfileImagePath(userId, ProfileImageSize.Large, extension); var mediumImagePath = AppFileManager.CalculateUserProfileImagePath(userId, ProfileImageSize.Medium, extension); var smallImagePath = AppFileManager.CalculateUserProfileImagePath(userId, ProfileImageSize.Small, extension); var sourceImageCropArea = cropInfo.GetSourceImageCropArea(); AppFileManager.RemoveUserProfileImages(userId, ProfileImageSize.Large, ProfileImageSize.Medium, ProfileImageSize.Small); ImageHelper.CropImage(originalImagePath, sourceImageCropArea, new Size(300, 300), largeImagePath); ImageHelper.CropImage(originalImagePath, sourceImageCropArea, new Size(80, 80), mediumImagePath); ImageHelper.CropImage(originalImagePath, sourceImageCropArea, new Size(40, 40), smallImagePath); File.Delete(originalImagePath); ProfileBiz.SetUserProfile(userId, ProfileKeyValueType.IsProfileImageSet, "1"); UnitOfWork.SaveChanges(); }
public void SaveUserOriginalProfileImage(UserIdentity user, Stream inputStream, out int imageWidth, out int imageHeight) { AppDirectoryManager.CreateUserProfileImageDirectory(user.UserId); using (var image = ValidateFileAndGenerateImage(inputStream)) { string previousOriginalImagePath; var imageFormat = ImageHelper.GetImageFormat(image); var extension = ImageHelper.GetImageFormatFileExtension(imageFormat); var newOriginalImagePath = AppFileManager.CalculateUserProfileImagePath(user.UserId, ProfileImageSize.Original, extension); if (AppFileManager.TryGetUserProfileImagePath(user.UserId, ProfileImageSize.Original, out previousOriginalImagePath)) { if (previousOriginalImagePath != newOriginalImagePath) { File.Delete(previousOriginalImagePath); } } image.Save(newOriginalImagePath, imageFormat); imageWidth = image.Width; imageHeight = image.Height; } }