-
-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add pdf thumbnail support (port #378) #543
Conversation
Co-Authored-By: Heiholf <[email protected]>
def replace_transparent_pixels( | ||
img: Image.Image, color: tuple[int, int, int, int] = (255, 255, 255, 255) | ||
) -> Image.Image: | ||
"""Replaces (copying/without mutating) all transparent pixels in an image with the color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Replaces (copying/without mutating) all transparent pixels in an image with the color. | |
"""Replace (copying/without mutating) all transparent pixels in an image with the color. |
"""Render a thumbnail for a PDF file. | ||
|
||
filepath (Path): The path of the file. | ||
size (tuple[int,int]): The size of the icon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type doesnt match the parameter (int
)
@@ -786,6 +798,52 @@ def _model_stl_thumb(self, filepath: Path, size: int) -> Image.Image: | |||
|
|||
return im | |||
|
|||
def _pdf_thumb(self, filepath: Path, size: int) -> Image.Image: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to have a test for this. Rather than explaining what and how, I made the test, so feel free to cherry-pick/merge it into the branch. But it looks like the final png isnt really transparent 🤔
Co-Authored-By: yed <[email protected]>
I noticed that on my machine (Windows 10) I had to regenerate the png preview to get the test to pass locally - it seems that for whatever reason, the text is aliased slightly differently when generating on my machine, resulting in a few different pixels that cause the test to fail. We may need to go with a different line of testing for this, or introduce a margin of error. I'd like to get your thoughts on this. |
perhaps generating the image in a higher resolution (parameter Another option could be to make the values for |
Changed the test to a black square, seems to be working both on my Windows machine and inside the workflow |
This PR is a port of #378 which previously targeted thumbnails/Alpha-v9.4 to main (aka v9.5x).
This adds thumbnail/preview support for PDF files.