feat(ui): krita/open raster thumbs (#985)

* added kra/krz media categories and thumb rendering logic

* added .ora support (follows open doc standard)

---------

Co-authored-by: fj92hg <>
This commit is contained in:
mashed5894
2025-08-01 09:53:35 +03:00
committed by GitHub
parent a7d98e765b
commit fd7d1f1e95
2 changed files with 37 additions and 0 deletions

View File

@@ -108,6 +108,7 @@ class MediaCategories:
".psd",
}
_AFFINITY_PHOTO_SET: set[str] = {".afphoto"}
_KRITA_SET: set[str] = {".kra", ".krz"}
_ARCHIVE_SET: set[str] = {
".7z",
".gz",
@@ -341,6 +342,7 @@ class MediaCategories:
".odp",
".ods",
".odt",
".ora",
}
_PACKAGE_SET: set[str] = {
".aab",
@@ -605,6 +607,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,
@@ -639,6 +647,7 @@ class MediaCategories:
SPREADSHEET_TYPES,
TEXT_TYPES,
VIDEO_TYPES,
KRITA_TYPES,
]
@staticmethod

View File

@@ -677,6 +677,29 @@ class ThumbRenderer(QObject):
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 @@ class ThumbRenderer(QObject):
# 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