diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-14 22:27:58 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-05-14 22:27:58 -0400 |
| commit | 2f4f8c105e57c11c48a6c840e6f3cbb11538d82d (patch) | |
| tree | c6a09ce5b211757ce96cbe6ed797f4d3074a61f3 /MediaBrowser.Controller/Drawing | |
| parent | bdc546ed85dfb8389184234ac74c6cc7b4046515 (diff) | |
update image processing
Diffstat (limited to 'MediaBrowser.Controller/Drawing')
| -rw-r--r-- | MediaBrowser.Controller/Drawing/IImageEncoder.cs | 11 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Drawing/ImageHelper.cs | 69 |
2 files changed, 71 insertions, 9 deletions
diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 830093fcf..64d997dba 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -15,18 +15,11 @@ namespace MediaBrowser.Controller.Drawing /// </summary> /// <value>The supported output formats.</value> ImageFormat[] SupportedOutputFormats { get; } + /// <summary> /// Encodes the image. /// </summary> - /// <param name="inputPath">The input path.</param> - /// <param name="outputPath">The output path.</param> - /// <param name="autoOrient">if set to <c>true</c> [automatic orient].</param> - /// <param name="width">The width.</param> - /// <param name="height">The height.</param> - /// <param name="quality">The quality.</param> - /// <param name="options">The options.</param> - /// <param name="outputFormat">The output format.</param> - void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat outputFormat); + void EncodeImage(string inputPath, ImageSize? originalImageSize, string outputPath, bool autoOrient, int quality, ImageProcessingOptions options, ImageFormat outputFormat); /// <summary> /// Creates the image collage. diff --git a/MediaBrowser.Controller/Drawing/ImageHelper.cs b/MediaBrowser.Controller/Drawing/ImageHelper.cs new file mode 100644 index 000000000..30c4e90fb --- /dev/null +++ b/MediaBrowser.Controller/Drawing/ImageHelper.cs @@ -0,0 +1,69 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Drawing; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.Drawing +{ + public static class ImageHelper + { + public static ImageSize GetNewImageSize(ImageProcessingOptions options, ImageSize? originalImageSize) + { + if (originalImageSize.HasValue) + { + // Determine the output size based on incoming parameters + var newSize = DrawingUtils.Resize(originalImageSize.Value, options.Width, options.Height, options.MaxWidth, options.MaxHeight); + + return newSize; + } + return GetSizeEstimate(options); + } + + private static ImageSize GetSizeEstimate(ImageProcessingOptions options) + { + if (options.Width.HasValue && options.Height.HasValue) + { + return new ImageSize(options.Width.Value, options.Height.Value); + } + + var aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item); + + var width = options.Width ?? options.MaxWidth; + + if (width.HasValue) + { + var heightValue = width.Value / aspect; + return new ImageSize(width.Value, heightValue); + } + + var height = options.Height ?? options.MaxHeight ?? 200; + var widthValue = aspect * height; + return new ImageSize(widthValue, height); + } + + private static double GetEstimatedAspectRatio(ImageType type, IHasImages item) + { + switch (type) + { + case ImageType.Art: + case ImageType.Backdrop: + case ImageType.Chapter: + case ImageType.Screenshot: + case ImageType.Thumb: + return 1.78; + case ImageType.Banner: + return 5.4; + case ImageType.Box: + case ImageType.BoxRear: + case ImageType.Disc: + case ImageType.Menu: + return 1; + case ImageType.Logo: + return 2.58; + case ImageType.Primary: + return item.GetDefaultPrimaryImageAspectRatio() ?? .667; + default: + return 1; + } + } + } +} |
