CommonNetFuncs.Images
4.0.9
See the version list below for details.
dotnet add package CommonNetFuncs.Images --version 4.0.9
NuGet\Install-Package CommonNetFuncs.Images -Version 4.0.9
<PackageReference Include="CommonNetFuncs.Images" Version="4.0.9" />
<PackageVersion Include="CommonNetFuncs.Images" Version="4.0.9" />
<PackageReference Include="CommonNetFuncs.Images" />
paket add CommonNetFuncs.Images --version 4.0.9
#r "nuget: CommonNetFuncs.Images, 4.0.9"
#:package CommonNetFuncs.Images@4.0.9
#addin nuget:?package=CommonNetFuncs.Images&version=4.0.9
#tool nuget:?package=CommonNetFuncs.Images&version=4.0.9
CommonNetFuncs.Images
This project contains helper methods for dealing with base64 image encoding and image optimization.
Contents
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>
| 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.9)
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.17 | 102 | 2/23/2026 |
| 4.0.15 | 102 | 2/8/2026 |
| 4.0.14 | 97 | 2/7/2026 |
| 4.0.13 | 99 | 2/6/2026 |
| 4.0.12 | 94 | 2/3/2026 |
| 4.0.10 | 103 | 1/24/2026 |
| 4.0.9 | 107 | 1/12/2026 |
| 4.0.6 | 102 | 1/2/2026 |
| 4.0.3 | 193 | 12/22/2025 |
| 4.0.2 | 843 | 12/2/2025 |
| 4.0.1 | 191 | 11/27/2025 |
| 4.0.0 | 185 | 11/23/2025 |
| 3.8.42 | 81 | 3/5/2026 |
| 3.8.38 | 98 | 2/24/2026 |
| 3.8.33 | 106 | 2/2/2026 |
| 3.8.32 | 101 | 2/2/2026 |
| 3.8.28 | 100 | 1/5/2026 |
| 3.8.20 | 596 | 12/1/2025 |
| 3.8.18 | 429 | 11/20/2025 |
| 3.8.16 | 415 | 11/17/2025 |