Pixsys.Library.Media.ImageManager
1.1.0
dotnet add package Pixsys.Library.Media.ImageManager --version 1.1.0
NuGet\Install-Package Pixsys.Library.Media.ImageManager -Version 1.1.0
<PackageReference Include="Pixsys.Library.Media.ImageManager" Version="1.1.0" />
<PackageVersion Include="Pixsys.Library.Media.ImageManager" Version="1.1.0" />
<PackageReference Include="Pixsys.Library.Media.ImageManager" />
paket add Pixsys.Library.Media.ImageManager --version 1.1.0
#r "nuget: Pixsys.Library.Media.ImageManager, 1.1.0"
#:package Pixsys.Library.Media.ImageManager@1.1.0
#addin nuget:?package=Pixsys.Library.Media.ImageManager&version=1.1.0
#tool nuget:?package=Pixsys.Library.Media.ImageManager&version=1.1.0
Image Manager
This manager will save and transform your images as a Fluent API, using SixLabors.ImageSharp library.
1. Installation
1.1 Register your settings in appsettings.json
Create a new section called ImageManager
and add the following properties:
Name | Optional? | Description |
---|---|---|
TemporaryFolder | Yes | Sets where the temporary image folder is located. Useful when you're working with uploaded images. |
Profiles | Yes | Sets all the profiles. Each profile contains a name, a array of sizes required for your needs, and a true/false property telling if you want to keep the original image when resizing. |
"ImageManager": {
"TemporaryFolder": "<TEMP_FOLDER>",
"Profiles": [
{
"Name": "<PROFILE_NAME>",
"Sizes": [
{
"Width": <WIDTH>,
"Height": <HEIGHT>
},
{
"Width": <WIDTH>,
"Height": <HEIGHT>
}
],
"KeepOriginalWhenResizing": <KEEP_ORIGINAL_WHEN_RESIZING>
},
{
"Name": "<PROFILE_NAME>",
"Sizes": [
{
"Width": <WIDTH>,
"Height": <HEIGHT>
},
{
"Width": <WIDTH>,
"Height": <HEIGHT>
}
],
"KeepOriginalWhenResizing": <KEEP_ORIGINAL_WHEN_RESIZING>
}
]
}
If profiles are set, the following image folder structure will be created:
├── <IMAGE_FOLDER>
│ ├── <PROFILE_1>
│ │ ├── <WIDTH_1xHEIGHT1> //ex: folder named '200x200'
│ │ │ ├── IMG
│ │ ├── <WIDTH_2xHEIGHT2>
│ │ │ ├── IMG
1.2 Register the service in Program.cs
using Pixsys.Library.Media.ImageManager;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
_ = builder.AddImageManager();
2 Usage
2.1 Inject the service into your controller
private readonly IImageManager _imageManager;
public MyController(IImageManager imageManager)
{
_imageManager = imageManager;;
}
2.2 Methods
First, you set if the image manager must process a server-stored image (ForImage
) or an uploaded one (FromFormFile
).
Then you can apply multiple manipulations (such as resize
,crop
,Sepia
,...) and/or save the output.
If you specify a profile name in the SaveImageAsync
method, it will create resized images in the 'profile name' folder.
2.2.1 Example
await _imageManager
.ForImage(<FILE_PATH>)
.BlackWhite()
.AutoOrient()
.Resize(new SixLabors.ImageSharp.Processing.ResizeOptions
{
Mode = SixLabors.ImageSharp.Processing.ResizeMode.Max,
Size = new Size(300, 400)
})
.Flip(SixLabors.ImageSharp.Processing.FlipMode.Horizontal)
.Grayscale()
.Polaroid()
.Vignette()
.Sepia()
.Pixelate()
.OilPaint()
.SaveImageAsync(new DirectoryInfo(webRootPath), "output", Pixsys.Library.Media.Common.Enums.ImageFormat.Webp, false, "test");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Pixsys.Library.Common (>= 1.0.0)
- Pixsys.Library.Media.Common (>= 1.0.0)
- SixLabors.ImageSharp (>= 3.1.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.