Skip to content

Generate a single thumbnail for multilayer tiff images #35

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mark-pitblado
Copy link

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 -flatten1? 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

  • Generate a multilayered tiff with imagemagick for testing
# Create individual images first
convert -size 200x200 xc:red -pointsize 20 -fill white -annotate +10+30 "Layer 1" layer1.png
convert -size 200x200 xc:green -pointsize 20 -fill white -annotate +10+30 "Layer 2" layer2.png
convert -size 200x200 xc:blue -pointsize 20 -fill white -annotate +10+30 "Layer 3" layer3.png

# Combine into multi-layer TIFF
convert layer1.png layer2.png layer3.png multilayer.tiff

# Clean up temporary files
rm layer1.png layer2.png layer3.png
  • Ensure that attachment preview mode is set to "Thumbnail" in User Preferences.
  • Using a specify instance connected to an asset server using the current docker image, save multilayer.tiff through the Specify GUI. Confirm that there is no thumbnail visible.
  • Enter the thumbnails directory (whether that is in a docker volume or on a folder on the disk) and see that there are three .png files generated, ending in -0 -1 and -2.
  • (Optional) reset the attachments thumbnail directory by deleting all existing files.
  • Switch the asset server to an image that incorporates the changes that are applied in this PR.
  • Save the multilayer.tiff file, observe that a thumbnail is now visible (it should be a red square that says Layer 1).
  • Enter the thumbnails directory and see that there is now just one .png file generated.

Footnotes

  1. 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.

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 directly. 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thumbnail images are inconsistently generated
1 participant