Debian Codegraph @

blurhash.egg-info/PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: blurhash
3 Version: 1.1.5
4 Summary: Pure-Python implementation of the blurhash algorithm.
5 Home-page: https://github.com/halcy/blurhash-python
6 Author: Lorenz Diener
7 Author-email: [email protected]
8 License: MIT
9 Keywords: blurhash graphics web_development
10 Classifier: Development Status :: 5 - Production/Stable
11 Classifier: Intended Audience :: Developers
12 Classifier: Topic :: Multimedia :: Graphics
13 Classifier: License :: OSI Approved :: MIT License
14 Classifier: Programming Language :: Python :: 2
15 Classifier: Programming Language :: Python :: 3
16 Description-Content-Type: text/markdown
17 License-File: LICENSE
18 Provides-Extra: test
19 Requires-Dist: pytest; extra == "test"
20 Requires-Dist: Pillow; extra == "test"
21 Requires-Dist: numpy; extra == "test"
22 Dynamic: author
23 Dynamic: author-email
24 Dynamic: classifier
25 Dynamic: home-page
26 Dynamic: keywords
27 Dynamic: license
28 Dynamic: license-file
29 Dynamic: provides-extra
30 Dynamic: summary
31
32 # blurhash-python
33 ```python
34 import blurhash
35 import PIL.Image
36 import numpy
37
38 PIL.Image.open("cool_cat_small.jpg")
39 # Result:
40 ```
41 ![A picture of a cool cat.](/cool_cat_small.jpg?raw=true "A cool cat.")
42 ```python
43 blurhash.encode(numpy.array(PIL.Image.open("cool_cat_small.jpg").convert("RGB")))
44 # Result: 'UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH'
45
46 PIL.Image.fromarray(numpy.array(blurhash.decode('UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH', 128, 128)).astype('uint8'))
47 # Result:
48 ```
49 ![Blurhash example output: A blurred cool cat.](/blurhash_example.png?raw=true "Blurhash example output: A blurred cool cat.")
50
51 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, which then can be used to quickly create a placeholder for images that are still loading or that should be hidden behind a content warning.
52
53 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). You can install it via pip:
54
55 ```bash
56 $ pip3 install blurhash
57 ```
58
59 It exports five functions:
60 * "encode" and "decode" do the actual en- and decoding of blurhash strings
61 * "components" returns the number of components x- and y components of a blurhash
62 * "srgb_to_linear" and "linear_to_srgb" are colour space conversion helpers
63
64 Have a look at example.py for an example of how to use all of these working together.
65
66 Documentation for each function:
67
68 ```python
69 blurhash.encode(image, components_x = 4, components_y = 4, linear = False):
70 """
71 Calculates the blurhash for an image using the given x and y component counts.
72
73 Image should be a 3-dimensional array, with the first dimension being y, the second
74 being x, and the third being the three rgb components that are assumed to be 0-255
75 srgb integers (incidentally, this is the format you will get from a PIL RGB image).
76
77 You can also pass in already linear data - to do this, set linear to True. This is
78 useful if you want to encode a version of your image resized to a smaller size (which
79 you should ideally do in linear colour).
80 """
81
82 blurhash.decode(blurhash, width, height, punch = 1.0, linear = False)
83 """
84 Decodes the given blurhash to an image of the specified size.
85
86 Returns the resulting image a list of lists of 3-value sRGB 8 bit integer
87 lists. Set linear to True if you would prefer to get linear floating point
88 RGB back.
89
90 The punch parameter can be used to de- or increase the contrast of the
91 resulting image.
92
93 As per the original implementation it is suggested to only decode
94 to a relatively small size and then scale the result up, as it
95 basically looks the same anyways.
96 """
97
98 blurhash.srgb_to_linear(value):
99 """
100 srgb 0-255 integer to linear 0.0-1.0 floating point conversion.
101 """
102
103 blurhash.linear_to_srgb(value):
104 """
105 linear 0.0-1.0 floating point to srgb 0-255 integer conversion.
106 """
107 ```