aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-10-27 22:32:42 -0400
committerLuke <luke.pulverenti@gmail.com>2015-10-27 22:32:42 -0400
commited0e1399fc785a3d4b1a161a84d2fcc8fff1e576 (patch)
tree34dd309d29257d4218bbbe801dd329620c00c3b2
parent4b771ddf7947917422b699e2f65e1ca33a3352ed (diff)
parent06efa32e8f83d46bfa482f89be49230782a3bb36 (diff)
Merge pull request #1229 from MediaBrowser/master
handle GetImageSize failure
-rw-r--r--Emby.Drawing/ImageProcessor.cs74
1 files changed, 69 insertions, 5 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index ba92e0388..a24987c05 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -214,12 +214,11 @@ namespace Emby.Drawing
dateModified = tuple.Item2;
}
- var originalImageSize = GetImageSize(originalImagePath, dateModified, true);
+ var newSizeInfo = GetNewImageSize(originalImagePath, dateModified, options);
+ var newSize = newSizeInfo.Item1;
+ var isSizeChanged = newSizeInfo.Item2;
- // Determine the output size based on incoming parameters
- var newSize = DrawingUtils.Resize(originalImageSize, options.Width, options.Height, options.MaxWidth, options.MaxHeight);
-
- if (options.HasDefaultOptionsWithoutSize(originalImagePath) && newSize.Equals(originalImageSize) && options.Enhancers.Count == 0)
+ if (options.HasDefaultOptionsWithoutSize(originalImagePath) && !isSizeChanged && options.Enhancers.Count == 0)
{
// Just spit out the original file if the new size equals the old
return originalImagePath;
@@ -267,6 +266,71 @@ namespace Emby.Drawing
return cacheFilePath;
}
+ private Tuple<ImageSize, bool> GetNewImageSize(string originalImagePath, DateTime dateModified, ImageProcessingOptions options)
+ {
+ try
+ {
+ var originalImageSize = GetImageSize(originalImagePath, dateModified, true);
+
+ // Determine the output size based on incoming parameters
+ var newSize = DrawingUtils.Resize(originalImageSize, options.Width, options.Height, options.MaxWidth, options.MaxHeight);
+
+ return new Tuple<ImageSize, bool>(newSize, !newSize.Equals(originalImageSize));
+ }
+ catch
+ {
+ return new Tuple<ImageSize, bool>(GetSizeEstimage(options), true);
+ }
+ }
+
+ private ImageSize GetSizeEstimage(ImageProcessingOptions options)
+ {
+ if (options.Width.HasValue && options.Height.HasValue)
+ {
+ return new ImageSize(options.Width.Value, options.Height.Value);
+ }
+
+ var aspect = GetEstimatedAspectRatio(options.Image.Type);
+
+ var width = options.Width ?? options.MaxWidth;
+
+ if (width.HasValue)
+ {
+ var heightValue = aspect / width.Value;
+ return new ImageSize(width.Value, Convert.ToInt32(heightValue));
+ }
+
+ var height = options.Height ?? options.MaxHeight ?? 200;
+ var widthValue = aspect * height;
+ return new ImageSize(Convert.ToInt32(widthValue), height);
+ }
+
+ private double GetEstimatedAspectRatio(ImageType type)
+ {
+ 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 .667;
+ default:
+ return 1;
+ }
+ }
+
private ImageFormat GetOutputFormat(ImageFormat requestedFormat)
{
if (requestedFormat == ImageFormat.Webp && !_imageEncoder.SupportedOutputFormats.Contains(ImageFormat.Webp))