SixLabors ImageSharp package.

This commit is contained in:
2021-06-18 10:48:47 +01:00
parent 8d3aa5ec03
commit b4f9962b21
3 changed files with 59 additions and 1 deletions
@@ -42,7 +42,7 @@ namespace Sarand.Net.Standard.Base.Helpers
// Data members.
private static readonly List<ContentTypeData> contentTypes;
private static FileExtensionContentTypeProvider provider = null;
private static readonly HashSet<Sacs.MimeType> allowedMimeTypes_CandidateCV = new HashSet<Sacs.MimeType>()
private static readonly HashSet<Sacs.MimeType> allowedMimeTypes_CV = new HashSet<Sacs.MimeType>()
{
Sacs.MimeType.MsDoc,
Sacs.MimeType.MsDocx,
+57
View File
@@ -0,0 +1,57 @@
using Sarand.Net.Standard.Base.App;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.Text;
namespace Sarand.Net.Standard.Base.Utils
{
//=======================================================================
// Image handling methods utilising SixLabors ImageSharp package.
//=======================================================================
public static class ImageUtils
{
//-------------------------------------------------------------------
private static readonly String className = typeof(ImageUtils).ToString();
//-------------------------------------------------------------------
public class ImageConfig
{
public byte[] ImageData { get; set; }
public bool ValidImage { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
public static ImageConfig VerifyImageData(byte[] imageData)
{
String fn = className + ".VerifyImageData";
ImageConfig imageConfig = new ImageConfig();
imageConfig.ImageData = imageData;
try
{
var image = Image.Load<Rgba32>(imageData);
if (image == null) return imageConfig;
imageConfig.Width = image.Width;
imageConfig.Height = image.Height;
imageConfig.ValidImage = true;
return imageConfig;
}
catch (Exception exc)
{
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
}
return imageConfig;
}
// Load from byte array.
public static Image LoadImage(byte[] imageData)
{
var image = Image.Load<Rgba32>(imageData);
return image;
}
//-------------------------------------------------------------------
}
//=======================================================================
}
+1
View File
@@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
</ItemGroup>
<ItemGroup>