Blurhash.net
The C#-Implementation of the Blurhash-Algorithm
Install / Use
/learn @MarkusPalcer/Blurhash.netREADME
BlurHash
BlurHash is a compact representation of a placeholder for an image.
Why would you want this?
Does your designer cry every time you load their beautifully designed screen, and it is full of empty boxes because all the images have not loaded yet? Does your database engineer cry when you want to solve this by trying to cram little thumbnail images into your data to show as placeholders?
BlurHash will solve your problems! How? Like this:
<img src="https://github.com/woltapp/blurhash/blob/master/Media/WhyBlurHash.png" width="600">You can also see nice examples and try it out yourself at blurha.sh!
How does it work?
In short, BlurHash takes an image, and gives you a short string (only 20-30 characters!) that represents the placeholder for this image. You do this on the backend of your service, and store the string along with the image. When you send data to your client, you send both the URL to the image, and the BlurHash string. Your client then takes the string, and decodes it into an image that it shows while the real image is loading over the network. The string is short enough that it comfortably fits into whatever data format you use. For instance, it can easily be added as a field in a JSON object.
In summary:
<img src="https://github.com/woltapp/blurhash/blob/master/Media/HowItWorks1.jpg" width="250"> <img src="https://github.com/woltapp/blurhash/blob/master/Media/HowItWorks2.jpg" width="250">
More Information
More information can be found in the base repository. Go there if you want to see the details on how BlurHash works or how to contribute your own port.
Usage
Using a supported image manipulation library
-
Install the NuGet-Package for your image manipulation library
- Install
Blurhash.System.Drawing.Commonif you're using theSystem.Drawing.Common-NuGet package. - Install
Blurhash.ImageSharpif you're usingSixLabors.ImageSharp - Install
Blurhash.Coreif you want to manually convert your image type for the algorithm (see below)
- Install
-
Call
Blurhasher.EncodeorBlurhasher.Decode
Using a Blurhash.NET with the IServiceCollection
- Install the NuGet-Package for your image manipulation library
- Install
Blurhash.Microsoft.Extensions.System.Drawingif you're using theSystem.Drawing.Common-NuGet package. - Install
Blurhash.Microsoft.Extensions.ImageSharpif you're using theSixLabors.ImageSharp - Install
Blurhash.Microsoft.Extensions.Coreif you want to manually convert your image type for the algorithm (see below)
- Install
Using an unsupported image manipulation library
Install the NuGet-Package Blurhash.Core (add Blurhash.Microsoft.Extensions.Core if you want to use dependency injection)
Encoding an image to a Blurhash string
- Write a method to convert an image from your library to a two-dimensional array of
Blurhash.Pixelwhere the first dimension is the X-Axis and the second dimension is the Y-Axis - Call
Blurhash.Core.Encodewith your array - Encapsulate this in a static
Encodemethod in a Library specificBlurhasherclass and share your implementation by creating a PullRequest
Decoding a Blurhash string into an image
- Write a method to convert a two-dimensional array of
Blurhash.Pixelto an image your library supports - Create a two-dimensional
Pixelarray where the first dimension is the desired witdh of the image and the second dimension is the desired height of the image - Call
Blurhash.Core.Decodewith this array and the input string. - Call your converter-method with the
Pixelarray filled byBlurhash.Core.Decode - Encapsulate this in a static
Decodemethod in a Library specificBlurhasherclass and share your implementation by creating a PullRequest
Sharing your code
Think about sharing your implementation, so others can use it too.
Calling it Blurhash.<Name of your image manipulation library> would help others to quickly find it on NuGet.org.
Versioning
Blurhash.NET uses Semantic Versioning (as explained https://semver.org)
Projects in this solution
This list does not contain the projects with names ending in .Test as they are the test projects for the ones listed here.
Blurhash.Core
The core algorithm of blurhash. For maximum compatibility this is a .NET-Standard project.Blurhash.System.Drawing.Common
Bridge-Library to use Blurhash with the System.Drawing.Common NuGet-Library in DotNetStandardBlurhash.ImageSharp
Bridge-Library to use Blurhash with ImageSharpBlurhash.Microsoft.Extensions.*
The respective libraries that enable usage of the blurhash algorithm with anIServiceCollectionBenchmarks
Used for benchmarking implementations during optimization runs
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
