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