diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-05-15 00:34:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-15 00:34:33 -0400 |
| commit | a4efcf07f42d1ccd2be0c2f4d2af1208366f6ab6 (patch) | |
| tree | c4d0a9693850b977b66c057508b286ed50da9a3c /MediaBrowser.Controller/Drawing | |
| parent | e2085763296e32e7ef1532460030e5449725116a (diff) | |
| parent | 4a8aa20698aa761cba7ab7e45181a2b3251fca64 (diff) | |
Merge pull request #2639 from MediaBrowser/beta
Beta
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; + } + } + } +} |
