Skip to content

Commit b88f087

Browse files
authored
Update README.md
1 parent ace4125 commit b88f087

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,35 @@ PIL.Image.fromarray(numpy.array(blurhash.decode("UBMOZfK1GG%LBBNG,;Rj2skq=eE1s9n
1919

2020
Blurhash is an algorithm that lets you transform image data into a small text representation of a blurred version of the image. This is useful since this small textual representation can be included when sending objects that may have images attached around, since it can be used to quickly create a placeholder for images that are still loading or that should be hidden behind a content warning.
2121

22-
This library contains a pure-python implementation of the blurhash algorithm, closely following the original swift implementation by Dag Ågren. The module has no dependencies (the unit tests require PIL and numpy). It exports only two functions, "encode" and "decode". You can find usage details here: TODO.
22+
This library contains a pure-python implementation of the blurhash algorithm, closely following the original swift implementation by Dag Ågren. The module has no dependencies (the unit tests require PIL and numpy). It exports only two functions, "encode" and "decode". The usage is as follows:
23+
24+
```python
25+
def blurhash.decode(blurhash, width, height, punch = 1.0, linear = False)
26+
"""
27+
Decodes the given blurhash to an image of the specified size.
28+
29+
Returns the resulting image a list of lists of 3-value sRGB 8 bit integer
30+
lists. Set linear to True if you would prefer to get linear floating point
31+
RGB back.
32+
33+
The punch parameter can be used to de- or increase the contrast of the
34+
resulting image.
35+
36+
As per the original implementation it is suggested to only decode
37+
to a relatively small size and then scale the result up, as it
38+
basically looks the same anyways.
39+
"""
40+
41+
def blurhash_encode(image, components_x = 4, components_y = 4, linear = False):
42+
"""
43+
Calculates the blurhash for an image using the given x and y component counts.
44+
45+
Image should be a 3-dimensional array, with the first dimension being y, the second
46+
being x, and the third being the three rgb components that are assumed to be 0-255
47+
srgb integers (incidentally, this is the format you will get from a PIL RGB image).
48+
49+
You can also pass in already linear data - to do this, set linear to True. This is
50+
useful if you want to encode a version of your image resized to a smaller size (which
51+
you should ideally do in linear colour).
52+
"""
53+
```

0 commit comments

Comments
 (0)