CommonNetFuncs.Images
4.0.40
See the version list below for details.
dotnet add package CommonNetFuncs.Images --version 4.0.40
NuGet\Install-Package CommonNetFuncs.Images -Version 4.0.40
<PackageReference Include="CommonNetFuncs.Images" Version="4.0.40" />
<PackageVersion Include="CommonNetFuncs.Images" Version="4.0.40" />
<PackageReference Include="CommonNetFuncs.Images" />
paket add CommonNetFuncs.Images --version 4.0.40
#r "nuget: CommonNetFuncs.Images, 4.0.40"
#:package CommonNetFuncs.Images@4.0.40
#addin nuget:?package=CommonNetFuncs.Images&version=4.0.40
#tool nuget:?package=CommonNetFuncs.Images&version=4.0.40
CommonNetFuncs.Images
This project contains helper methods for dealing with base64 image encoding and image optimization.
Contents
- CommonNetFuncs.Images
Base64
Helper methods for dealing with Base64 image encoding.
Base64 Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
ConvertImageFileToBase64
Converts an image file or stream to a Base64 string.
string base64String = ConvertImageFileToBase64(@"C:\path\to\image.jpg"); // Returns the Base64 string representation of the image file.
CleanImageValue [Obsolete, please use ExtractBase64]
Attempts to clean a Base64 string by removing any metadata or unwanted characters that may come with it when reading from an HTML element.
string base64String = "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
string? cleanedBase64 = CleanImageValue(base64String); // "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
ExtractBase64
Attempts to clean a CSS background image containing a Base64 string by removing any metadata or unwanted characters that may come with it when reading from an HTML element. Validates that the Base64 string is a valid image format.
string base64String = "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
string? cleanedBase64 = base64String.ExtractBase64(); // "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
ImageSaveToFile
Save a Base64 string to an image file.
string base64String = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
ImageSaveToFile(base64String, @"C:\path\to\output_image.png"); // Saves the Base64 string as an image file at the specified path.
IsValidBase64Image
Checks to see if a Base64 string is a valid image format.
string base64String = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
bool isValid = IsValidBase64Image(base64String); // true
</details>
Manipulation
Helper methods for manipulating images, such as resizing, and changing image quality.
Manipulation Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
ResizeImage
Resizes an image to the specified width and height, maintaining the aspect ratio if desired.
await ResizeImage(@"C:\path\to\input_image.jpg", @"C:\path\to\output_image.jpg", 800, 600); // "C:\path\to\output_image.jpg" contains the 800px x 600px resized image.
ConvertImageFormat
Converts an image from one format to another (e.g., JPEG to PNG).
await ConvertImageFormat(@"C:\path\to\input_image.jpg", @"C:\path\to\output_image.png", PngFormat.Instance); // "C:\path\to\output_image.png" contains the converted image in png format.
ReduceImageQuality
Reduces the quality of an image by applying a specified JPEG quality level, which can help in reducing file size. Neither input nor output are required to be JPEG format.
await ReduceImageQuality(@"C:\path\to\input_image.jpg", @"C:\path\to\output_image.jpg", 50); // "C:\path\to\output_image.jpg" contains the image with reduced 50% quality
TryDetectImageType
Detects the image format of a file based on its content, returning the format as a string.
TryDetectImageType(@"C:\path\to\input_image.jpg", out IImageFormat? format); // Returns true and format is the "JPEG" IImageFormat.
TryGetMetadata
Attempts to retrieve ImageMetadata from an image file.
TryGetMetadata(@"C:\path\to\input_image.jpg", out ImageMetadata metadata); // Returns ImageMetadata with properties like Width, Height, Format, etc.
</details>
Optimizer
Helper methods for optimizing images.
Optimizer Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
OptimizeImage
Optimizes an image by reducing its file size without sacrificing quality using gifsicle, jpegoptim, or optipng CLI tools depending on the image format.
await OptimizeImage(@"C:\path\to\input_image.jpg", @"C:\path\to\output_image.jpg"); // "C:\path\to\output_image.jpg" contains the optimized image.
</details>
Installation
Install via NuGet:
dotnet add package CommonNetFuncs.Images
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- CommonNetFuncs.Core (>= 4.0.40)
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 |
|---|---|---|
| 4.0.55 | 0 | 5/30/2026 |
| 4.0.54 | 43 | 5/30/2026 |
| 4.0.53 | 56 | 5/28/2026 |
| 4.0.51 | 100 | 5/27/2026 |
| 4.0.50 | 92 | 5/26/2026 |
| 4.0.43 | 105 | 5/14/2026 |
| 4.0.40 | 112 | 5/10/2026 |
| 4.0.39 | 105 | 5/10/2026 |
| 4.0.37 | 107 | 5/9/2026 |
| 4.0.36 | 100 | 5/8/2026 |
| 4.0.31 | 129 | 4/21/2026 |
| 4.0.29 | 103 | 4/20/2026 |
| 4.0.28 | 99 | 4/19/2026 |
| 4.0.25 | 110 | 4/3/2026 |
| 4.0.23 | 108 | 3/30/2026 |
| 4.0.17 | 120 | 2/23/2026 |
| 3.8.45 | 106 | 3/30/2026 |
| 3.8.42 | 108 | 3/5/2026 |
| 3.8.38 | 117 | 2/24/2026 |