using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;

namespace NetinaShop.Core.Utilities;

public static class ImageConvertor
{
    public static async Task<Stream> ImageResize(this FileUploadRequest fileUpload, Stream input, Stream output, int newWidth)
    {
        using var image = await Image.LoadAsync(input);
        var height_width = image.Height / image.Width;
        var new_Height = newWidth * height_width;
        image.Mutate(x => x.Resize(newWidth, new_Height));
        image.Mutate(x => x.Resize(newWidth, new_Height));
        await image.SaveAsJpegAsync(output);
        return output;
    }
}