Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions Quaver.API/Maps/AutoMod/AutoMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using Quaver.API.Maps.Structures;
using Quaver.API.Replays;
using Quaver.API.Replays.Virtual;
using SixLabors.ImageSharp;
using SkiaSharp;

namespace Quaver.API.Maps.AutoMod
{
Expand Down Expand Up @@ -445,15 +445,33 @@ private void DetectImageFileIssues(string item, string path, int maxSize, int mi
if (new FileInfo(path).Length > maxSize)
Issues.Add(new AutoModIssueImageTooLarge(item, maxSize));

if (!TryGetImageDimensions(path, out var width, out var height))
return;

if (width < minWidth || height < minHeight || width > maxWidth || height > maxHeight)
Issues.Add(new AutoModIssueImageResolution(item, minWidth, minHeight, maxWidth, maxHeight));
}

private static bool TryGetImageDimensions(string path, out int width, out int height)
{
width = 0;
height = 0;

try
{
using (var image = Image.Load(path))
if (image.Width < minWidth || image.Height < minHeight || image.Width > maxWidth || image.Height > maxHeight)
Issues.Add(new AutoModIssueImageResolution(item, minWidth, minHeight, maxWidth, maxHeight));
using (var codec = SKCodec.Create(path))
{
if (codec == null)
return false;

width = codec.Info.Width;
height = codec.Info.Height;
return width > 0 && height > 0;
}
}
catch (Exception)
{
// ignored
return false;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Quaver.API/Quaver.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<PackageReference Include="MonoGame.Extended" Version="1.1.0" />
<PackageReference Include="MoonSharp" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
<PackageReference Include="SkiaSharp" Version="4.148.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="4.148.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.5.231" />
<PackageReference Include="YamlDotNet" Version="5.1.0" />
<PackageReference Include="z440.atl.core" Version="3.18.0" />
Expand Down
Loading