private static void SetUserPhotoThumbnailSettings(Guid userId, int width, int height) { var settings = UserPhotoThumbnailSettings.LoadForUser(userId); if (!settings.IsDefault) { return; } var max = Math.Max(Math.Max(width, height), SmallFotoSize.Width); var min = Math.Max(Math.Min(width, height), SmallFotoSize.Width); var pos = (max - min) / 2; settings = new UserPhotoThumbnailSettings( width >= height ? new Point(pos, 0) : new Point(0, pos), new Size(min, min)); settings.SaveForUser(userId); }
private static string SizePhoto(Guid userID, byte[] data, long maxFileSize, Size size, bool now) { if (data == null || data.Length <= 0) { throw new UnknownImageFormatException(); } if (maxFileSize != -1 && data.Length > maxFileSize) { throw new ImageWeightLimitException(); } var resizeTask = new ResizeWorkerItem(userID, data, maxFileSize, size, GetDataStore(), UserPhotoThumbnailSettings.LoadForUser(userID)); if (now) { //Resize synchronously ResizeImage(resizeTask); return(GetSizedPhotoAbsoluteWebPath(userID, size)); } else { if (!ResizeQueue.GetItems().Contains(resizeTask)) { //Add ResizeQueue.Add(resizeTask); if (!ResizeQueue.IsStarted) { ResizeQueue.Start(ResizeImage); } } return(GetDefaultPhotoAbsoluteWebPath(size)); //NOTE: return default photo here. Since task will update cache } }