CommonNetFuncs.Images
3.6.19
See the version list below for details.
dotnet add package CommonNetFuncs.Images --version 3.6.19
NuGet\Install-Package CommonNetFuncs.Images -Version 3.6.19
<PackageReference Include="CommonNetFuncs.Images" Version="3.6.19" />
<PackageVersion Include="CommonNetFuncs.Images" Version="3.6.19" />
<PackageReference Include="CommonNetFuncs.Images" />
paket add CommonNetFuncs.Images --version 3.6.19
#r "nuget: CommonNetFuncs.Images, 3.6.19"
#:package CommonNetFuncs.Images@3.6.19
#addin nuget:?package=CommonNetFuncs.Images&version=3.6.19
#tool nuget:?package=CommonNetFuncs.Images&version=3.6.19
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 | net9.0 is compatible. 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. |
-
net9.0
- CommonNetFuncs.Core (>= 3.6.19)
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 |
---|---|---|
3.6.20 | 85 | 7/30/2025 |
3.6.19 | 87 | 7/28/2025 |
3.6.18 | 315 | 7/25/2025 |
3.6.6 | 432 | 7/21/2025 |
3.6.5 | 118 | 7/16/2025 |
3.6.4 | 122 | 7/16/2025 |
3.6.3 | 119 | 7/16/2025 |
3.6.2 | 132 | 7/15/2025 |
3.6.1 | 131 | 7/14/2025 |
3.6.0 | 152 | 7/14/2025 |
3.5.3 | 136 | 7/10/2025 |
3.5.0 | 146 | 7/7/2025 |
3.4.23 | 141 | 6/26/2025 |
3.4.21 | 130 | 6/26/2025 |
3.4.20 | 132 | 6/25/2025 |
3.4.18 | 148 | 6/23/2025 |
3.4.13 | 242 | 6/13/2025 |
3.4.8 | 285 | 6/11/2025 |
3.4.2 | 146 | 6/2/2025 |
3.4.1 | 85 | 5/30/2025 |
3.4.0 | 139 | 5/30/2025 |
3.3.11 | 147 | 5/19/2025 |
3.3.10 | 230 | 5/13/2025 |
3.3.0 | 162 | 4/29/2025 |
3.2.22 | 188 | 3/12/2025 |
3.2.20 | 231 | 3/7/2025 |
3.2.15 | 117 | 2/24/2025 |
3.2.13 | 124 | 2/13/2025 |
3.2.9 | 108 | 2/4/2025 |
3.2.4 | 107 | 1/21/2025 |
3.2.0 | 109 | 12/19/2024 |
3.1.2 | 157 | 12/13/2024 |
3.1.0 | 137 | 12/6/2024 |
3.0.0 | 123 | 12/3/2024 |
2.1.3 | 102 | 12/3/2024 |
2.1.2 | 109 | 12/3/2024 |
2.1.0 | 113 | 12/2/2024 |
2.0.5 | 118 | 11/26/2024 |
2.0.3 | 113 | 11/19/2024 |
2.0.2 | 111 | 11/18/2024 |
2.0.1 | 112 | 11/15/2024 |
2.0.0 | 103 | 11/14/2024 |
1.0.47 | 116 | 11/14/2024 |
1.0.42 | 148 | 11/12/2024 |
1.0.40 | 117 | 11/12/2024 |
1.0.37 | 125 | 11/4/2024 |
1.0.31 | 116 | 10/31/2024 |
1.0.28 | 111 | 10/25/2024 |
1.0.26 | 169 | 10/18/2024 |
1.0.25 | 103 | 10/17/2024 |
1.0.24 | 107 | 10/17/2024 |
1.0.18 | 116 | 10/11/2024 |
1.0.17 | 141 | 9/27/2024 |
1.0.16 | 114 | 9/27/2024 |
1.0.14 | 122 | 9/23/2024 |
1.0.13 | 128 | 9/18/2024 |
1.0.12 | 117 | 9/18/2024 |
1.0.11 | 113 | 9/18/2024 |
1.0.10 | 128 | 9/11/2024 |
1.0.9 | 120 | 9/11/2024 |
1.0.8 | 137 | 9/11/2024 |
1.0.7 | 133 | 9/11/2024 |
1.0.1 | 133 | 9/4/2024 |
1.0.0 | 129 | 9/2/2024 |