Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/tagstudio/qt/previews/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,9 @@ def __cover_from_comic_info(
if cover is not None:
pages = [f for f in archive.namelist() if f != "ComicInfo.xml"]
page_name = pages[int(unwrap(cover.get("Image")))]
if page_name.endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg")):
if page_name.lower().endswith(
(".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp")
):
image_data = archive.read(page_name)
im = Image.open(BytesIO(image_data))

Expand Down Expand Up @@ -1006,7 +1008,9 @@ def __first_image(archive: _Archive) -> Image.Image | None:
Image: The first renderable image in the archive.
"""
for file_name in archive.namelist():
if file_name.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg")):
if file_name.lower().endswith(
(".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp")
):
image_data = archive.read(file_name)
return Image.open(BytesIO(image_data))

Expand Down
39 changes: 39 additions & 0 deletions tests/qt/test_thumb_renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: (c) TagStudio Contributors
# SPDX-License-Identifier: GPL-3.0-only


from io import BytesIO
from pathlib import Path
from zipfile import ZipFile

from PIL import Image

from tagstudio.qt.previews.renderer import ThumbRenderer


def _write_webp_archive(archive_path: Path) -> None:
image_data = BytesIO()
Image.new("RGB", (2, 2), "red").save(image_data, format="WEBP")

with ZipFile(archive_path, "w") as archive:
archive.writestr("cover.webp", image_data.getvalue())


def test_archive_thumb_extracts_webp_image(tmp_path: Path):
archive_path = tmp_path / "webp_only.zip"
_write_webp_archive(archive_path)

thumbnail = ThumbRenderer._archive_thumb(archive_path, ".zip")

assert thumbnail is not None
assert thumbnail.size == (2, 2)


def test_epub_cover_extracts_webp_image_from_cbz(tmp_path: Path):
archive_path = tmp_path / "webp_only.cbz"
_write_webp_archive(archive_path)

thumbnail = ThumbRenderer._epub_cover(archive_path, ".cbz")

assert thumbnail is not None
assert thumbnail.size == (2, 2)
Loading