MartinDrozdik.Services.ImageSaving
1.0.0
See the version list below for details.
dotnet add package MartinDrozdik.Services.ImageSaving --version 1.0.0
NuGet\Install-Package MartinDrozdik.Services.ImageSaving -Version 1.0.0
<PackageReference Include="MartinDrozdik.Services.ImageSaving" Version="1.0.0" />
paket add MartinDrozdik.Services.ImageSaving --version 1.0.0
#r "nuget: MartinDrozdik.Services.ImageSaving, 1.0.0"
// Install MartinDrozdik.Services.ImageSaving as a Cake Addin #addin nuget:?package=MartinDrozdik.Services.ImageSaving&version=1.0.0 // Install MartinDrozdik.Services.ImageSaving as a Cake Tool #tool nuget:?package=MartinDrozdik.Services.ImageSaving&version=1.0.0
Image saving service for quick use
A service to save your images to disk with little effort. It solves the problem with resizing and quality handling.
Setup
Add the saver to your service collection or straight up instantiate it like a bad boy.
builder.Services.AddImageSaver();
var saver = new ImageSaver();
Usage
Use the following interface:
public interface IImageSaver
{
Task Save(string path, Stream imageData);
Task Save(string path, Stream imageData, IImageConfiguration config);
}
It will save a stream to a path like /you/have/ligma.png
.
The awesome part is the IImageConfiguration
. Checkout what properties this baby can fit in:
public interface IImageConfiguration
{
int Height { get; set; }
int Width { get; set; }
int MaxHeight { get; set; }
int MaxWidth { get; set; }
int Quality { get; set; }
}
The saver will try to match your set width/height properties. If you set only one dimension (width/height), the aspect ratio will be preserved!
The quality should be in the range 1-100 and is applied for formats that support it (jpeg, webm).
var saver = new ImageSaver();
await imageSaver.Save(imagePath, image, new ImageConfiguration()
{
MaxWidth = 50,
Quality = 80
});
Under the hood
It uses ImageSharp for all image operations, and that's it.
Checkout the project with tests.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- SixLabors.ImageSharp (>= 2.1.1)
- SixLabors.ImageSharp.Drawing (>= 1.0.0-beta14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.