Generate a single thumbnail for multilayer tiff images #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #33
When there is more than one layer in a tiff file, ImageMagick's convert will generate multiple files as output, with a
-0
,-1
(and so on) suffix. This causes a 404 error when specify goes to search for the thumbnails, and produces excess images in the thumbnails directory. This commit checks if there are multiple layers in the tiff, and if so, uses the first layer to generate the thumbnail (similar to how PDF thumbnails are handled). There isn't any reason to choose the first layer over the second, but one has to be picked.I am not sure if we should use
-background
with-flatten
1? With the testing multilayered tiff, the output is the blue Layer 3, but without solid coloured squares, it may have a different effect.This PR should fix thumbnail preview for institutions on a retroactive basis as thumbnails are requested. However, it doesn't clean up existing thumbnails with the
-0
or-1
suffix already in the thumbnail directory. Those will have to be cleaned up by an IT personal.Formatting changes are ruff, if black is preferred I can run black over it.
Testing instructions
multilayer.tiff
through the Specify GUI. Confirm that there is no thumbnail visible..png
files generated, ending in-0
-1
and-2
.multilayer.tiff
file, observe that a thumbnail is now visible (it should be a red square that says Layer 1)..png
file generated.Footnotes
From the docs - Create a canvas the size of the first images virtual canvas using the current -background color, and -compose each image in turn onto that canvas. Images falling outside that canvas is clipped. Final image will have a zero virtual canvas offset.
This usually used as one of the final 'image layering' operations overlaying all the prepared image layers into a final image.
For a single image this method can also be used to fillout a virtual canvas with real pixels, or to underlay an opaque color to remove transparency from an image. ↩