An Image Resizer used with DotNetBrightener.SimpleUploadService package. Migrated to SkiaSharp for improved security and performance.
$ dotnet add package DotNetBrightener.UploadService.ImageOptimizerImage optimization and resizing functionality for DotNetBrightener Upload Service.
Version 2026.0.1+ has migrated from Magick.NET to SkiaSharp due to security vulnerability CVE-2025-65955.
services.AddUploadService(config)
.UseImageMagickOptimizer(); // ⚠️ Deprecated - shows warning
services.AddUploadService(config)
.UseSkiaSharpOptimizer(); // ✅ Use this instead
dotnet add package DotNetBrightener.UploadService.ImageOptimizer
using Microsoft.Extensions.DependencyInjection;
// In your Startup.cs or Program.cs
services.AddUploadService(configuration)
.UseSkiaSharpOptimizer();
services.AddUploadService(configuration)
.UseSkiaSharpOptimizer()
.ConfigureUploadOptions(options =>
{
options.MaxFileSize = 10 * 1024 * 1024; // 10MB
options.AllowedFileExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".webp" };
});
No changes needed if using centralized package management. The package will automatically use SkiaSharp.
Before:
services.AddUploadService(config)
.UseImageMagickOptimizer();
After:
services.AddUploadService(config)
.UseSkiaSharpOptimizer();
The old UseImageMagickOptimizer() method still works but:
[Obsolete] warning during compilationUseSkiaSharpOptimizer()SkiaSharp supports the following image formats:
public class SkiaSharpImageOptimizer : IImageResizer
{
/// <summary>
/// Resizes an image from the input stream to the specified dimensions
/// </summary>
/// <param name="inputStream">The input image stream</param>
/// <param name="newWidth">The target width (absolute value will be used)</param>
/// <param name="newHeight">The target height (absolute value will be used)</param>
/// <returns>A new stream containing the resized image in PNG format</returns>
Stream ResizeImageFromStream(Stream inputStream, int newWidth, int newHeight);
}
// Recommended method
public static UploadServiceConfigurationBuilder UseSkiaSharpOptimizer(
this UploadServiceConfigurationBuilder builder);
// Deprecated method (backward compatibility)
[Obsolete("Use UseSkiaSharpOptimizer instead")]
public static UploadServiceConfigurationBuilder UseImageMagickOptimizer(
this UploadServiceConfigurationBuilder builder);
The package includes comprehensive unit tests:
To run tests:
cd src/UploadService/DotNetBrightener.UploadService.ImageOptimizer.Tests
dotnet test
SkiaSharp provides excellent performance characteristics:
SKFilterQuality.HighCause: The input stream doesn't contain a valid image or format is not supported.
Solution: Verify the input stream contains valid image data and is in a supported format.
Cause: Invalid target dimensions or corrupted source image.
Solution: Ensure width and height are positive integers and source image is valid.
This package is part of the DotNetBrightener Framework.
© 2017 - 2025 Vampire Coder (formerly DotNet Brightener)
For issues, questions, or contributions: