TagStudio icon indicating copy to clipboard operation
TagStudio copied to clipboard

SVG thumbnail renderer

Open Tyrannicodin opened this issue 1 year ago • 5 comments

Adds an SVG renderer for thumbnails using Qt's QSvgRenderer that writes to a QImage that is written onto a QBuffer that PIL can then read as an image. ~~However, it does have an issue that I have been unable to resolve: Sometimes thumbnails seem to write over each other or otherwise be corrupted (no affect on the actual files though). I think it's due to the QPainter painting in a thread, but I'm not sure. You can see an example of this problem below:~~

Image no longer relevant

Tyrannicodin avatar Sep 04 '24 02:09 Tyrannicodin

Sometimes thumbnails seem to write over each other or otherwise be corrupted

Yeah, that sounds like a multithreading issue since the thumb_renderer is multithreaded

CyanVoxel avatar Sep 04 '24 02:09 CyanVoxel

@CyanVoxel I wonder if a future change would make sense, add a context manager so that it handles the buildup and teardown of thumbnails.

eivl avatar Sep 04 '24 16:09 eivl

nice work, but as always - when adding a new feature, please add a test.

For this one having some sample .svg image alongside the test, and then compare the output via syrupy that it really provides the expected output. I made a similar test in some other project, so it could look something like this:

from syrupy.extensions.image import PNGImageSnapshotExtension


def test_svg_to_png(snapshot):
    file_path = Path(__file__).parent / "fixtures" / "sample.svg"

    png_image = ThumbRenderer(...)._image_vector_thumb(file_path, 600)
    assert png_image.read() == snapshot(extension_class=PNGImageSnapshotExtension)

yedpodtrzitko avatar Sep 13 '24 12:09 yedpodtrzitko

also what's the git branch thumbnails? Wouldnt be better to aim this either to the Alpha-9.4 or main?

yedpodtrzitko avatar Sep 13 '24 12:09 yedpodtrzitko

I'm moved this PR from the deprecated thumbnails branch to Alpha-v9.4, which is the branch that thumbnails was eventually merged into. However the v9.4.x releases are now feature frozen and are now solely reserved for bugfixes. This means that after the changes from thumbnails are ported to main that I'll once again be moving the target for this PR over to there as a v9.5 feature.

Sorry for the disruption, and thank you for your patience.

CyanVoxel avatar Sep 15 '24 08:09 CyanVoxel

I've ported this functionality to main via #540, thank you for your contribution with this!

CyanVoxel avatar Oct 14 '24 20:10 CyanVoxel