aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 27acbaa..d725dd9 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -25,6 +25,7 @@ from cryptography.hazmat.primitives.asymmetric import ec
25import http_ece 25import http_ece
26import base64 26import base64
27import json 27import json
28import blurhash
28 29
29try: 30try:
30 from urllib.parse import urlparse 31 from urllib.parse import urlparse
@@ -2315,7 +2316,42 @@ class Mastodon:
2315 ) 2316 )
2316 2317
2317 return json.loads(decrypted.decode('utf-8'), object_hook = Mastodon.__json_hooks) 2318 return json.loads(decrypted.decode('utf-8'), object_hook = Mastodon.__json_hooks)
2318 2319
2320 ###
2321 # Blurhash utilities
2322 ###
2323 def decode_blurhash(self, media_dict, out_size = (16, 16), size_per_component = True, return_linear = True):
2324 """
2325 Basic media-dict blurhash decoding.
2326
2327 out_size is the desired result size in pixels, either absolute or per blurhash
2328 component (this is the default).
2329
2330 By default, this function will return the image as linear RGB, ready for further
2331 scaling operations. If you want to display the image directly, set return_linear
2332 to False.
2333
2334 Returns the decoded blurhash image as a three-dimensional list: [height][width][3],
2335 with the last dimension being RGB colours.
2336
2337 For further info and tips for advanced usage, refer to the documentation for the
2338 blurhash module: https://github.com/halcy/blurhash-python
2339 """
2340 # Figure out what size to decode to
2341 decode_components_x, decode_components_y = blurhash.components(media_dict["blurhash"])
2342 if size_per_component == False:
2343 decode_size_x = out_size[0]
2344 decode_size_y = out_size[1]
2345 else:
2346 decode_size_x = decode_components_x * out_size[0]
2347 decode_size_y = decode_components_y * out_size[1]
2348
2349 # Decode
2350 decoded_image = blurhash.decode(media_dict["blurhash"], decode_size_x, decode_size_y, linear = return_linear)
2351
2352 # And that's pretty much it.
2353 return decoded_image
2354
2319 ### 2355 ###
2320 # Pagination 2356 # Pagination
2321 ### 2357 ###
Powered by cgit v1.2.3 (git 2.41.0)