Skip to content

Commit

Permalink
#7626 Added handling for common FormatExceptions with Skia loading sv… (
Browse files Browse the repository at this point in the history
#9581)

Co-authored-by: Shadowghost <Shadowghost@users.noreply.github.com>
  • Loading branch information
JPVenson and Shadowghost committed Apr 10, 2023
1 parent 15c8854 commit 3c22d5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ public async Task UpdateImagesAsync(BaseItem item, bool forceUpdate = false)
catch (Exception ex)
{
_logger.LogError(ex, "Cannot get image dimensions for {ImagePath}", image.Path);
size = new ImageDimensions(0, 0);
size = default;
image.Width = 0;
image.Height = 0;
}
Expand Down
18 changes: 14 additions & 4 deletions src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,18 @@ public ImageDimensions GetImageSize(string path)
if (extension.Equals(".svg", StringComparison.OrdinalIgnoreCase))
{
var svg = new SKSvg();
svg.Load(path);
return new ImageDimensions(Convert.ToInt32(svg.Picture.CullRect.Width), Convert.ToInt32(svg.Picture.CullRect.Height));
try
{
svg.Load(path);
return new ImageDimensions(Convert.ToInt32(svg.Picture.CullRect.Width), Convert.ToInt32(svg.Picture.CullRect.Height));
}
catch (FormatException skiaColorException)
{
// This exception is known to be thrown on vector images that define custom styles
// Skia SVG is not able to handle that and as the repository is quite stale and has not received updates we just catch them
_logger.LogDebug(skiaColorException, "There was a issue loading the requested svg file");
return default;
}
}

using var codec = SKCodec.Create(path, out SKCodecResult result);
Expand All @@ -132,10 +142,10 @@ public ImageDimensions GetImageSize(string path)
return new ImageDimensions(info.Width, info.Height);
case SKCodecResult.Unimplemented:
_logger.LogDebug("Image format not supported: {FilePath}", path);
return new ImageDimensions(0, 0);
return default;
default:
_logger.LogError("Unable to determine image dimensions for {FilePath}: {SkCodecResult}", path, result);
return new ImageDimensions(0, 0);
return default;
}
}

Expand Down

0 comments on commit 3c22d5c

Please sign in to comment.