#247·blurhash

Dynamically determine X and Y components based on aspect ratio

Author: simplenotezyCreated Nov 23, 2023Updated Feb 6, 2024
Labelsdocumentation

According to the documentation:

How do I pick the number of X and Y components?

It depends a bit on taste. The more components you pick, the more information is retained in the placeholder, but the longer the BlurHash string will be. Also, it doesn't always look good with too many components. We usually go with 4 by 3, which seems to strike a nice balance.

However, you should adjust the number of components depending on the aspect ratio of your images. For instance, very wide images should have more X components and fewer Y components.

The Swift example project contains a test app where you can play around with the parameters and see the results.

Did anybody come up with a simple formula we can use to come up with proper X and Y components dynamically based on width/height?