This repository has been archived on 2023-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
2chBackAPI/DBControllers/ImageController.cs
RakVhalate 35139d66a2
All checks were successful
continuous-integration/drone/push Build is passing
Refactoring
2022-12-13 19:18:23 +05:00

37 lines
1.0 KiB
C#

using SkiaSharp;
namespace NeDvachAPI.DBControllers
{
public class ImageController
{
public static bool CheckExtention(string extentionToCheck)
{
var supportedTypes = new[] { ".jpg", ".png", ".jpeg" };
if (supportedTypes.Contains(extentionToCheck.ToLower()))
{
return true;
}
else return false;
}
public static bool ResizeImage(string picPath, string smallPath, int width, int height)
{
var dstInfo = new SKImageInfo(height, width);
var bitmap = SKBitmap.Decode(picPath);
var image = SKImage.FromBitmap(bitmap.Resize(dstInfo, SKFilterQuality.Medium));
var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);
using (var stream = new FileStream(smallPath, FileMode.Create, FileAccess.Write))
data.SaveTo(stream);
data.Dispose();
image.Dispose();
bitmap.Dispose();
return true;
}
}
}