diff --git a/src/tagstudio/core/media_types.py b/src/tagstudio/core/media_types.py index f13ce2a0d..e418a56f1 100644 --- a/src/tagstudio/core/media_types.py +++ b/src/tagstudio/core/media_types.py @@ -93,6 +93,7 @@ class MediaCategories: ".psd", } _AFFINITY_PHOTO_SET: set[str] = {".afphoto"} + _KRITA_SET: set[str] = {".kra", ".krz"} _ARCHIVE_SET: set[str] = { ".7z", ".gz", @@ -326,6 +327,7 @@ class MediaCategories: ".odp", ".ods", ".odt", + ".ora", } _PACKAGE_SET: set[str] = { ".aab", @@ -590,6 +592,12 @@ class MediaCategories: is_iana=True, name="video", ) + KRITA_TYPES = MediaCategory( + media_type=MediaType.IMAGE, + extensions=_KRITA_SET, + is_iana=False, + name="krita", + ) ALL_CATEGORIES = [ ADOBE_PHOTOSHOP_TYPES, @@ -624,6 +632,7 @@ class MediaCategories: SPREADSHEET_TYPES, TEXT_TYPES, VIDEO_TYPES, + KRITA_TYPES, ] @staticmethod diff --git a/src/tagstudio/qt/widgets/thumb_renderer.py b/src/tagstudio/qt/widgets/thumb_renderer.py index e4ec1e8d0..f0be2a09e 100644 --- a/src/tagstudio/qt/widgets/thumb_renderer.py +++ b/src/tagstudio/qt/widgets/thumb_renderer.py @@ -677,6 +677,29 @@ def _open_doc_thumb(filepath: Path) -> Image.Image: return im + @staticmethod + def _krita_thumb(filepath: Path) -> Image.Image: + """Extract and render a thumbnail for an Krita file. + + Args: + filepath (Path): The path of the file. + """ + file_path_within_zip = "preview.png" + im: Image.Image = None + with zipfile.ZipFile(filepath, "r") as zip_file: + # Check if the file exists in the zip + if file_path_within_zip in zip_file.namelist(): + # Read the specific file into memory + file_data = zip_file.read(file_path_within_zip) + thumb_im = Image.open(BytesIO(file_data)) + if thumb_im: + im = Image.new("RGB", thumb_im.size, color="#1e1e1e") + im.paste(thumb_im) + else: + logger.error("Couldn't render thumbnail", filepath=filepath) + + return im + @staticmethod def _powerpoint_thumb(filepath: Path) -> Image.Image | None: """Extract and render a thumbnail for a Microsoft PowerPoint file. @@ -1366,6 +1389,11 @@ def _render( # PowerPoint Slideshow elif ext in {".pptx"}: image = self._powerpoint_thumb(_filepath) + # Krita ======================================================== + elif MediaCategories.is_ext_in_category( + ext, MediaCategories.KRITA_TYPES, mime_fallback=True + ): + image = self._krita_thumb(_filepath) # OpenDocument/OpenOffice ====================================== elif MediaCategories.is_ext_in_category( ext, MediaCategories.OPEN_DOCUMENT_TYPES, mime_fallback=True