123123
This commit is contained in:
@@ -10,7 +10,6 @@ namespace ZelWiki.Library
|
||||
|
||||
public static string SanitizeAccountName(string fileName, char[]? extraInvalidCharacters = null)
|
||||
{
|
||||
// Get array of invalid characters for file names
|
||||
var invalidChars = Path.GetInvalidFileNameChars().ToList();
|
||||
|
||||
if (extraInvalidCharacters != null)
|
||||
@@ -27,7 +26,7 @@ namespace ZelWiki.Library
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Take a height and width and enforces a max on both dimensions while maintaining the ratio.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="originalWidth"></param>
|
||||
/// <param name="originalHeight"></param>
|
||||
@@ -35,20 +34,16 @@ namespace ZelWiki.Library
|
||||
/// <returns></returns>
|
||||
public static (int Width, int Height) ScaleToMaxOf(int originalWidth, int originalHeight, int maxSize)
|
||||
{
|
||||
// Calculate aspect ratio
|
||||
float aspectRatio = (float)originalWidth / originalHeight;
|
||||
|
||||
// Determine new dimensions based on the larger dimension
|
||||
var aspectRatio = (float)originalWidth / originalHeight;
|
||||
|
||||
int newWidth, newHeight;
|
||||
if (originalWidth > originalHeight)
|
||||
{
|
||||
// Scale down the width to the maxSize and calculate the height
|
||||
newWidth = maxSize;
|
||||
newHeight = (int)(maxSize / aspectRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scale down the height to the maxSize and calculate the width
|
||||
newHeight = maxSize;
|
||||
newWidth = (int)(maxSize * aspectRatio);
|
||||
}
|
||||
@@ -72,7 +67,7 @@ namespace ZelWiki.Library
|
||||
public static byte[] ConvertHttpFileToBytes(IFormFile image)
|
||||
{
|
||||
using var stream = image.OpenReadStream();
|
||||
using BinaryReader reader = new BinaryReader(stream);
|
||||
using var reader = new BinaryReader(stream);
|
||||
return reader.ReadBytes((int)image.Length);
|
||||
}
|
||||
|
||||
@@ -80,7 +75,7 @@ namespace ZelWiki.Library
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
return [];
|
||||
}
|
||||
|
||||
using var compressedStream = new MemoryStream();
|
||||
@@ -88,15 +83,15 @@ namespace ZelWiki.Library
|
||||
{
|
||||
compressor.Write(data, 0, data.Length);
|
||||
}
|
||||
|
||||
return compressedStream.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
return [];
|
||||
|
||||
|
||||
using var compressedStream = new MemoryStream(data);
|
||||
using var decompressor = new GZipStream(compressedStream, CompressionMode.Decompress);
|
||||
@@ -105,4 +100,4 @@ namespace ZelWiki.Library
|
||||
return decompressedStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user