weaver.transform.utils
Module Contents
- weaver.transform.utils.is_image(image: str) bool[source]
Check if the file is an image based on its MIME content type.
- Parameters:
image – The file name or path.
- Returns:
True if the file is an image, False otherwise.
- weaver.transform.utils.is_svg(image: str) bool[source]
Check if the file is an SVG image based on its MIME content type.
- Parameters:
image – The file name or path.
- Returns:
True if the file is SVG, False otherwise.
- weaver.transform.utils.is_png(image: str) bool[source]
Check if the file is a PNG image based on its MIME content type.
- Parameters:
image – The file name or path.
- Returns:
True if the file is PNG, False otherwise.
- weaver.transform.utils.is_tiff(image: str) bool[source]
Check if the file is a TIFF image based on its MIME content type.
- Parameters:
image – The file name or path.
- Returns:
True if the file is TIFF, False otherwise.
- weaver.transform.utils.is_gif(image: str) bool[source]
Check if the file is a GIF image based on its MIME content type.
- Parameters:
image – The file name or path.
- Returns:
True if the file is GIF, False otherwise.
- weaver.transform.utils.get_content(file_path: str, mode: str = 'r') str[source]
Retrieve the content of a file.
- Parameters:
file_path – The path to the file.
mode – The mode in which to open the file. Defaults to “r”.
- Returns:
The content of the file as a string.
- weaver.transform.utils.write_content(file_path: str, content: str | dict) None[source]
Write content to a file.
- Parameters:
file_path – The path to the file.
content – The content to write, can be a string or dictionary.
- weaver.transform.utils.write_images(images: List[PIL.Image.Image], output_file: str, ext: str = 'png') None[source]
Save a list of images to an archive or single file.
- Parameters:
images – A list of images to save.
output_file – The output file name or path.
ext – The image format (extension). Defaults to “png”.
- weaver.transform.utils.extend_alternate_formats(formats, conversion_dict=None)[source]
Extend a list of formats with missing alternate formats while preserving the original order.
- Parameters:
formats – A list of format dictionaries containing the “mediaType” key.
conversion_dict – A dictionary mapping media types to their alternate formats. If None, uses the default CONVERSION_DICT.
- Returns:
The extended list of formats with alternate formats added in a consistent order.