CommonNetFuncs.Images
4.1.14
See the version list below for details.
dotnet add package CommonNetFuncs.Images --version 4.1.14
NuGet\Install-Package CommonNetFuncs.Images -Version 4.1.14
<PackageReference Include="CommonNetFuncs.Images" Version="4.1.14" />
<PackageVersion Include="CommonNetFuncs.Images" Version="4.1.14" />
<PackageReference Include="CommonNetFuncs.Images" />
paket add CommonNetFuncs.Images --version 4.1.14
#r "nuget: CommonNetFuncs.Images, 4.1.14"
#:package CommonNetFuncs.Images@4.1.14
#addin nuget:?package=CommonNetFuncs.Images&version=4.1.14
#tool nuget:?package=CommonNetFuncs.Images&version=4.1.14
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.
ResizeTo Helpers
Use lightweight helper overloads when you just need a resized SKBitmap (and optionally encoded output).
using FileStream input = File.OpenRead(@"C:\path\to\input_image.jpg");
using MemoryStream output = new();
// Stream -> SKBitmap
using SKBitmap resizedA = input.ResizeTo(320, 240);
// Stream -> SKBitmap + encoded output stream
using SKBitmap resizedB = input.ResizeTo(output, 320, 240, SKEncodedImageFormat.Jpeg, 90);
// SKBitmap -> resized SKBitmap
using SKBitmap sourceBitmap = SKBitmap.Decode(@"C:\path\to\input_image.jpg");
using SKBitmap resizedC = sourceBitmap.ResizeTo(320, 240);
// SKImage -> resized SKBitmap
using SKImage sourceImage = SKImage.FromBitmap(sourceBitmap);
using SKBitmap resizedD = sourceImage.ResizeTo(320, 240);
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", SKEncodedImageFormat.Png); // "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 SKEncodedImageFormat? format); // Returns true and format is Jpeg.
TryGetMetadata
Attempts to retrieve ImageMetadata from an image file.
TryGetMetadata(@"C:\path\to\input_image.jpg", out ImageInfo metadata); // Returns ImageInfo with properties like Width, Height, and EncodedFormat.
</details>
Fingerprinting
Helper methods for perceptual image fingerprinting and duplicate detection using AverageHash, DifferenceHash, and PerceptualHash.
Fingerprinting Usage Examples
<details> <summary><h3>Usage Examples</h3></summary>
FingerprintImage
Fingerprint a single file path.
ImageFingerprint fp = await @"C:\path\to\image.jpg".FingerprintImage(ImageHashAlgorithm.DifferenceHash);
// fp.Hash contains the 64-bit perceptual hash value
FingerprintDirectory
Fingerprint all supported images in a directory.
IReadOnlyList<ImageFingerprint> fingerprints = await ImageFingerprinting.FingerprintDirectory(
@"C:\path\to\images",
recursive: true,
algorithm: ImageHashAlgorithm.PerceptualHash
);
Compare and FindDuplicates
Compare two fingerprints or scan a set for duplicates.
SimilarityResult pair = ImageFingerprinting.Compare(fingerprints[0], fingerprints[1], duplicateThreshold: 90.0m);
IReadOnlyList<SimilarityResult> duplicates = ImageFingerprinting.FindDuplicates(fingerprints, duplicateThreshold: 90.0m);
IReadOnlyList<SimilarityResult> duplicatesFromDirectory = await ImageFingerprinting.FindDuplicatesInDirectory(
@"C:\path\to\images",
recursive: true,
algorithm: ImageHashAlgorithm.DifferenceHash
);
</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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CommonNetFuncs.Core (>= 4.1.13)
-
net10.0
- CommonNetFuncs.Core (>= 4.1.13)
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.3.2 | 47 | 8/14/2026 |
| 4.3.1 | 88 | 8/10/2026 |
| 4.3.0 | 103 | 8/3/2026 |
| 4.1.17 | 94 | 8/3/2026 |
| 4.1.14 | 90 | 7/31/2026 |
| 4.1.13 | 101 | 7/27/2026 |
| 4.1.12 | 110 | 7/16/2026 |
| 4.1.11 | 111 | 7/9/2026 |
| 4.1.8 | 119 | 7/7/2026 |
| 4.1.6 | 120 | 6/15/2026 |
| 4.1.0 | 123 | 6/5/2026 |
| 4.0.55 | 120 | 5/30/2026 |
| 4.0.54 | 119 | 5/30/2026 |
| 4.0.53 | 129 | 5/28/2026 |
| 4.0.51 | 125 | 5/27/2026 |
| 4.0.50 | 127 | 5/26/2026 |
| 4.0.43 | 272 | 5/14/2026 |
| 4.0.40 | 129 | 5/10/2026 |
| 4.0.39 | 117 | 5/10/2026 |