Webimages
This library can be used to download webimages in parallel before establishing products to reduce renderingtime due to serial downloads. Images should be placed with frame::image( ... updateFlags=16)
Get started by initializing an WebImageBundle Object. Takes a list of urls (optional) and a URLMarker-Enum (optional). URLs can be added individually or existing ones overridden as well after initializing the Object.
To download the webimages, use download_queue. This saves the images to the filesystem and saves the url-paths to the corresponding Webimages in the "queue".
When placing the image into a frame, the url should be processed by the function get_webimage_url with parameter check_preloads = True.
If an asset referenced in the datafile is not a webimage but sent with the payload of the renderpdf-request to priint:cloud (as zip-file), the path of the file can be retrieved by using the function get_path_of_zip_payload.
Enum URLMarker
These Enums contain the keys for "nameflags" for webimages as described in the comet-docu. It is recommended to use some way of filename-shortening (for example "only hash" or "ellipsize end") to avoid runnung into problems with too long filepaths.
| Enum | Value |
|---|---|
NONE | "" |
ELLIPSIZE_START | "kEllipsizeStart" |
ELLIPSIZE_MIDDLE | "kEllipsizeMiddle" |
ELLIPSIZE_END | "kEllipsizeEnd" |
NO_HASH_ELLIPSIZE_END | "kNoHashkEllipsizeEnd" |
NO_HASH | "kNoHash" |
ONLY_HASH | "kOnlyHash" |
Functions
get_webimage_url(...)
(url, check_preloads = True, add_mediaproxy = True, nameflag = URLMarker.ONLY_HASH)
Retrieves the webimage-url of a given URL. If a file from that URL was preloaded using the WebImageBundle-class, an absolute path is retrieved from the cached URL / path-values. If no local path can be returned, the mediaproxy and specified nameflag are added to the URL.
| Parameters: | url (str) The webimage-URL that should be processed by this function. |
| check_preloads (bool) Whether or not to retrieve the local filepath of a preloaded file. | |
| add_mediaproxy (bool) Whether or not to append the url to the mediaproxy-url of priint:cloud. | |
| nameflag (URLMarker) The URLMarker, that should be appended to the url, to modify the filename-length. It is recommended to use a URLMarker to avoid problems due to too long filepaths. For the available _URLMarker_s check URLMarker-Enum. | |
| Returns: | A url with added components or local filepath of preloaded file. |
| Return Type: | str |
get_urlmarker(...)
(urlmarker_str)
Retrieves an Enum by its string-value from the URLMarker-Enum.
| Parameters: | urlmarker_str (str) A string-value of a URLMarker-Enum. |
| Returns: | An Enum of URLMarker. |
| Return Type: | URLMarker |
get_path_of_zip_payload(...)
(relative_path)
Retrieves a path of a file from a zip-payload sent with the renderpdf-request. The files of zip-payloads are stored in the priint:cloud-ticket's folder and can be accessed by giving a relative path for the structure in the zip-file.
| Parameters: | relative_path (str) A relative path to a file in the structure of the zip-file sent as ticket-palyoad. |
| Returns: | The absolute path of the file in the ticket-folder. |
| Return Type: | str |
Class WebImage
WebImage(...)
(url, nameflag = URLMarker.NONE, add_mediaproxy = True)
Creates an instance of WebImage.
| Parameters: | url (str) The URL of a webimage. |
| nameflag (URLMarker) The nameflag / URLMarker to add to the URL. | |
| add_mediaproxy (bool) Whether or not to use the priint:cloud-mediaproxy with the url. | |
| Returns: | Instance of WebImage |
| Return Type: | WebImage |
create_download_url()
Create a download-url of this WebImage using the url-, nameflag- and add_mediaproxy-properties.
| Returns: | A URL with components as given at object initialization. |
| Return Type: | str |
get_download_url()
Get the download-url of this WebImage. If not created yet, it will be created using the url-, nameflag- and add_mediaproxy-properties.
| Returns: | A URL with components as given at object initialization. |
| Return Type: | str |
Class WebImageBundle
WebImageBundle(...)
(urls = None, nameflag = URLMarker.NONE, add_mediaproxy = True, clear_cache = False)
| Parameters: | urls (list[str]) A list of URLs for webimages. |
| nameflag (URLMarker) A URLMarker that should be applied to all URLs to modify filename-length. Default is URLMarker.ONLY_HASH | |
| add_mediaproxy (bool) Whether or not to use the priint:cloud's mediaproxy for downloads. | |
| clear_cache (bool) Whether or not to remove all previously cached urls / paths. | |
| Returns: | Instance of WebImageBundle. |
| Return Type: | WebImageBundle |
add_to_queue(...)
(item, override_duplicates = True)
Adds a WebImage-object to the internal queue-property of the object. Can override or omit in case of duplicates.
| Parameters: | item (WebImage) The WebImage-object to be added to the queue. |
| override_duplicates (bool) Whether or not to override an existing WebImage with the same url in the queue. Can be used to change the nameflag- or mediaproxy-options of a WebImage that is already in the queue. | |
| Returns: | Instance of WebImageBundle. |
| Return Type: | WebImageBundle |
download_queue()
Download all queue-items by creating their-webimage-urls as inputs and using the function comet.file.downloadWebImages. Saves the filepaths from the function's results and saves the final item-list in the comet module's variable comet.my_webimages_vars["preload_cache"].
| Returns: | Instance of WebImageBundle. |
| Return Type: | WebImageBundle |
evaluate_downloads(...)
(download_results)
Adds the local filepaths of downloaded files to the WebImage-objects from the queue by matching URLs.
| Parameters: | download_results (List[Tuple[str, str, int]]) The result returned by comet.file.downloadWebImages: A list of results containing [URL, Path to local result file, Error code] |
| Returns: | The updated queue-list. |
| Return Type: | list[WebImage] |
get_cached_path(...)
(url)
Retrieves the cached file system path for a given URL from the preloaded cache.
| Parameters: | url (str) The URL for which the cached path is requested |
| Returns: | The corresponding file system path if the URL exists in the cache; otherwise, None. |
| Return Type: | str|None |
get_cached_results()
Returns the current dictionary of preloaded URL-to-path mappings from the comet module's variable: comet.my_webimages_vars["preload_cache"].
| Returns: | A dictionary mapping URLs (str) to their respective local file system paths (str). |
| Return Type: | dict |
cache_results()
Populates and stores a URL-to-path mapping in the shared module cache. Iterates through the current processing queue (self.queue) and builds a dictionary of image URLs and their corresponding file system paths. This mapping is then stored in comet.my_webimages_vars["preload_cache"] for future retrieval.
| Returns: | None |
| Return Type: | None |
clear_cache()
Removes all previously cached urls / paths from the variable of the comet-module: comet.my_webimages_vars["preload_cache"]
| Returns: | None |
| Return Type: | None |