mickael-kerjean / filestash

🦄 A file manager / web client for SFTP, S3, FTP, WebDAV, Git, Minio, LDAP, CalDAV, CardDAV, Mysql, Backblaze, ...
https://www.filestash.app/
GNU Affero General Public License v3.0
9.91k stars 734 forks source link

[bug] Thumbnail not displaying for some image files #713

Open akadoura-zyres opened 1 month ago

akadoura-zyres commented 1 month ago

I've noticed an issue where the thumbnail is not being displayed for some image files and couldn't figure out what the reason. Instead of showing the generated thumbnail, the default thumbnail image of src="/assets/icons/placeholder.png" is being used.

Observation: These images contain some custom metadata (shown below), and the thumbnail shows again after the metadata removal.

Screenshot 2024-07-11 120341

Could you please investigate why this is happening?

zyAmo commented 1 month ago

Hi, I investigated this and found, that it is likely an issue with handling a JPEG which uses the CMYK colorspace. This only applies to the plg_image_c and is not present in plg_image_golang. A simple workaround is to use the latter.

Looking down further into the image_c code, it seems the relevant part is the hardcoded colorspace property in server/plugin/plg_image_c/image_jpeg.c:101

  jpeg_config_output.in_color_space = JCS_RGB;

Replacing this with

  jpeg_config_output.in_color_space = jpeg_config_input.out_color_space;

which effectively uses the colorspace from the input image for the output image, should do the trick. Although, I did not test this thoroughly, with many different JPEGs, just my sample.

Checking the colorspace of the input image and the generated thumbnail:

$ magick identify -verbose image.jpg | grep Colorspace # original
  Colorspace: CMYK
$ magick identify -verbose image_thumbnail.jpg | grep Colorspace # downloaded thumbnail
  Colorspace: CMYK

I didn't create a pull request since it's just a one-line change, but I can definitely do it if you'd like.

Have a nice weekend, everyone ✌️

mickael-kerjean commented 3 weeks ago

wow that's pretty cool, happy to accept a PR for this

zyAmo commented 3 weeks ago

PR created at https://github.com/mickael-kerjean/filestash/pull/723