Răsfoiți Sursa

Try to use Width and Height from ImageInfo to determine aspect ratio

cvium 3 ani în urmă
părinte
comite
d10de5b7f9
1 a modificat fișierele cu 16 adăugiri și 24 ștergeri
  1. 16 24
      Emby.Server.Implementations/Dto/DtoService.cs

+ 16 - 24
Emby.Server.Implementations/Dto/DtoService.cs

@@ -1398,41 +1398,33 @@ namespace Emby.Server.Implementations.Dto
                 return null;
                 return null;
             }
             }
 
 
-            ImageDimensions size;
-
-            var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio();
-
-            if (defaultAspectRatio > 0)
-            {
-                return defaultAspectRatio;
-            }
-
             if (!imageInfo.IsLocalFile)
             if (!imageInfo.IsLocalFile)
             {
             {
-                return null;
+                return item.GetDefaultPrimaryImageAspectRatio();
             }
             }
 
 
-            try
-            {
-                size = _imageProcessor.GetImageDimensions(item, imageInfo);
+            var width = imageInfo.Width;
+            var height = imageInfo.Height;
 
 
-                if (size.Width <= 0 || size.Height <= 0)
+            // Fallback to the image processor if the image info is somehow incorrect
+            if (width <= 0 || height <= 0)
+            {
+                try
                 {
                 {
-                    return null;
+                    var size = _imageProcessor.GetImageDimensions(item, imageInfo);
+                    width = size.Width;
+                    height = size.Height;
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogError(ex, "Failed to determine primary image aspect ratio for {ImagePath}", imageInfo.Path);
+                    return item.GetDefaultPrimaryImageAspectRatio();
                 }
                 }
-            }
-            catch (Exception ex)
-            {
-                _logger.LogError(ex, "Failed to determine primary image aspect ratio for {0}", imageInfo.Path);
-                return null;
             }
             }
 
 
-            var width = size.Width;
-            var height = size.Height;
-
             if (width <= 0 || height <= 0)
             if (width <= 0 || height <= 0)
             {
             {
-                return null;
+                return item.GetDefaultPrimaryImageAspectRatio();
             }
             }
 
 
             return (double)width / height;
             return (double)width / height;