/// <summary> /// Compare rotation type /// </summary> /// <param name="propertyName">name of property e.g. Rotation</param> /// <param name="sourceIndexItem">source object</param> /// <param name="oldRotationValue">oldRotationValue to compare with newRotationValue</param> /// <param name="newRotationValue">oldRotationValue to compare with newRotationValue</param> /// <param name="differenceList">list of different values</param> private static void CompareRotation(string propertyName, FileIndexItem sourceIndexItem, FileIndexItem.Rotation oldRotationValue, FileIndexItem.Rotation newRotationValue, List <string> differenceList) { if (oldRotationValue == newRotationValue || newRotationValue == FileIndexItem.Rotation.DoNotChange) { return; } sourceIndexItem.GetType().GetProperty(propertyName).SetValue(sourceIndexItem, newRotationValue, null); differenceList.Add(propertyName.ToLowerInvariant()); }
public async Task <bool> WriteAndCropFile(string fileHash, OffsetModel offsetData, int sourceWidth, int sourceHeight, FileIndexItem.Rotation rotation, string reference = null) { try { using (var thumbnailStream = new MemoryStream(offsetData.Data, offsetData.Index, offsetData.Count)) using (var smallImage = await Image.LoadAsync(thumbnailStream)) using (var outputStream = new MemoryStream()) { var smallImageWidth = smallImage.Width; var smallImageHeight = smallImage.Height; var result = NewImageSize.NewImageSizeCalc(smallImageWidth, smallImageHeight, sourceWidth, sourceHeight); smallImage.Mutate( i => i.Resize(smallImageWidth, smallImageHeight, KnownResamplers.Lanczos3) .Crop(new Rectangle(result.DestX, result.DestY, result.DestWidth, result.DestHeight))); var larger = (int)Math.Round(result.DestWidth * 1.2, 0); smallImage.Mutate( i => i.Resize(larger, 0, KnownResamplers.Lanczos3)); var rotate = RotateEnumToDegrees(rotation); smallImage.Mutate( i => i.Rotate(rotate)); await smallImage.SaveAsJpegAsync(outputStream); await _thumbnailStorage.WriteStreamAsync(outputStream, ThumbnailNameHelper.Combine(fileHash, ThumbnailSize.TinyMeta)); if (_appSettings.ApplicationType == AppSettings.StarskyAppType.WebController) { _logger.LogInformation($"[WriteAndCropFile] fileHash: {fileHash} is written"); } } return(true); } catch (Exception ex) { var message = ex.Message; if (message.StartsWith("Image cannot be loaded")) { message = "Image cannot be loaded"; } _logger.LogError($"[WriteFile@meta] Exception {reference} {message}", ex); return(false); } }
internal float RotateEnumToDegrees(FileIndexItem.Rotation rotation) { // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (rotation) { case FileIndexItem.Rotation.Rotate180: return(180); case FileIndexItem.Rotation.Rotate90Cw: return(90); case FileIndexItem.Rotation.Rotate270Cw: return(270); default: return(0); } }
public Task <bool> WriteAndCropFile(string fileHash, OffsetModel offsetData, int sourceWidth, int sourceHeight, FileIndexItem.Rotation rotation, string reference = null) { return(Task.FromResult(true)); }