MartinDrozdik.Services.ImageSaving 1.0.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MartinDrozdik.Services.ImageSaving" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MartinDrozdik.Services.ImageSaving --version 1.0.0                
#r "nuget: MartinDrozdik.Services.ImageSaving, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.2 417 9/3/2022
1.3.1 385 9/3/2022
1.3.0 384 9/3/2022
1.2.0 393 8/3/2022
1.1.3 413 7/7/2022
1.1.2 409 7/7/2022
1.1.1 419 4/29/2022
1.1.0 419 4/29/2022
1.0.1 391 4/29/2022
1.0.0 398 4/29/2022