mirrorworld.util¶
- get_image(url, session=None)[source]¶
Fetches an image from a URL using requests.
- Parameters:
url (str) – The URL.
session (Session) – (optional) A requests session.
- Returns:
The image as PIL Image.
- Return type:
Image
- async get_image_async(url, session)[source]¶
Fetches an image from a URL using aiohttp.
- Parameters:
url (str) – The URL.
session (ClientSession) – A
ClientSession.- Returns:
The image as PIL Image.
- Return type:
Image
- get_json(url, session=None, preprocess_function=None, headers=None)[source]¶
Fetches JSON from a GET endpoint using requests.
- Parameters:
- Returns:
The requested document as dictionary.
- Return type:
- async get_json_async(url, session, json_function_parameters=None, preprocess_function=None, headers=None)[source]¶
Fetches JSON from a GET endpoint using aiohttp.
- Parameters:
url (str) – The URL.
session (ClientSession) – A
ClientSession.json_function_parameters (dict) – (optional) Parameters to pass to the
ClientResponse.jsonfunction.preprocess_function (Callable) – (optional) A function to run on the text before passing it to the JSON parser.
headers (dict) – (optional) Request headers.
- Returns:
The requested document as dictionary.
- Return type:
- post_json(url, body, session=None, preprocess_function=None, headers=None)[source]¶
Fetches JSON from a POST endpoint using requests.
- Parameters:
- Returns:
The requested document as dictionary.
- Return type:
- async post_json_async(url, body, session, json_function_parameters=None, preprocess_function=None, headers=None)[source]¶
Fetches JSON from a POST endpoint using aiohttp.
- Parameters:
url (str) – The URL.
body (any) – The post body.
session (ClientSession) – A
ClientSession.json_function_parameters (dict) – (optional) Parameters to pass to the
ClientResponse.jsonfunction.preprocess_function (Callable) – (optional) A function to run on the text before passing it to the JSON parser.
headers (dict) – (optional) Request headers.
- Returns:
The requested document as dictionary.
- Return type:
- get_equirectangular_panorama(width, height, tile_size, tile_list, headers=None)[source]¶
Downloads and stitches a tiled equirectangular panorama.
- Parameters:
- Returns:
The stitched panorama as PIL image.
- Return type:
Image
- async get_equirectangular_panorama_async(width, height, tile_size, tile_list, session, headers=None)[source]¶
Downloads and stitches a tiled equirectangular panorama.
- Parameters:
- Returns:
The stitched panorama as PIL image.
- Return type:
Image
- try_get(accessor)[source]¶
QoL function for accessing an element of a nested list which may or may not exist, e.g.
foo[1][0][2][3].
- Parameters:
accessor – A function which attempts to access the element, e.g.
lambda: foo[1][0][2][3].- Returns:
The return value of the accessor, unless an IndexError, TypeError or KeyError occurred, in which case the function returns None.
- async download_files_async(urls, session=None, headers=None)[source]¶
Downloads multiple files to a list of
bytes.
- stitch_equirectangular_tiles(tile_images, width, height, tile_width, tile_height)[source]¶
Stitches downloaded tiles of a tiled equirectangular panorama to a full image.
- Parameters:
- Returns:
The stitched panorama as PIL image.
- Return type:
Image
- class CubemapStitchingMethod(*values)[source]¶
Stitching options for the faces of a cubemap.
- NONE = 0¶
The faces are returned as a list.
- NET = 1¶
The faces are combined into one image arranged as a net of a cube.
- ROW = 2¶
The faces are combined into one image arranged in one row in the order front, right, back, left, top, bottom.
- stitch_cubemap_faces(faces, face_size, stitching_method)[source]¶
Stitches the six faces of a cubemap into one image.
- Parameters:
faces (List[Image]) – A list of faces in the order front, right, back, left, top, bottom.
face_size (int) – The side length of one face of the cubemap in pixels.
stitching_method (CubemapStitchingMethod) – The stitching method.
- Returns:
A stitched image, or
facesif the stitching method isNONE.- Return type:
Image | List[Image]
- save_cubemap_panorama(pano, path, pil_args)[source]¶
Saves a cubemap to disk.
- Parameters:
pano (List[Image] | Image) – A stitched cubemap, or the six faces of a cubemap.
path (str) – The output path.
pil_args (dict) – (optional) Additional arguments for PIL’s Image.save method, e.g.
{"quality":100}. Defaults to{}.- Return type:
None