-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add pdf thumbnail support Co-Authored-By: Heiholf <[email protected]> * fix: remove redef * tests: add test comparing pdf to png snapshot Co-Authored-By: yed <[email protected]> * fix: fix info in docstrings * fix: remove sample png generation * fix: change the pdf snapshot to use a black square * chore: fix whitespace --------- Co-authored-by: Heiholf <[email protected]> Co-authored-by: yed <[email protected]>
- Loading branch information
1 parent
9255a86
commit 3d7629b
Showing
5 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (C) 2024 Travis Abendshien (CyanVoxel). | ||
# Licensed under the GPL-3.0 License. | ||
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio | ||
|
||
import numpy as np | ||
from PIL import Image | ||
|
||
|
||
def replace_transparent_pixels( | ||
img: Image.Image, color: tuple[int, int, int, int] = (255, 255, 255, 255) | ||
) -> Image.Image: | ||
"""Replace (copying/without mutating) all transparent pixels in an image with the color. | ||
Args: | ||
img (Image.Image): | ||
The source image | ||
color (tuple[int, int, int, int]): | ||
The color (RGBA, 0 to 255) which transparent pixels should be set to. | ||
Defaults to white (255, 255, 255, 255) | ||
Returns: | ||
Image.Image: | ||
A copy of img with the pixels replaced. | ||
""" | ||
pixel_array = np.asarray(img.convert("RGBA")).copy() | ||
pixel_array[pixel_array[:, :, 3] == 0] = color | ||
return Image.fromarray(pixel_array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+1.82 KB
tagstudio/tests/qt/__snapshots__/test_thumb_renderer/test_pdf_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters