3rd / image.nvim

🖼️ Bringing images to Neovim.
MIT License
1.03k stars 42 forks source link

JPEG Header detection supports only JFIF, but not variations such as EXIF, SPIFF, Adobe JPEG and other #131

Closed Elvyria closed 7 months ago

Elvyria commented 7 months ago

Hi. Image in my markdown file wasn't showing up and I found out that image.nvim doesn't detect it as image, because magic.lua only detects .jpg files with the header of FF D8 FF E0 which refers only to JPEG/JFIF version of JPEG.

My file header is FF D8 FF E1 - JPEG/EXIF.

Since there are multiple different ways of solving this issue I come with an issue and not a PR.

Useful related links: https://www.garykessler.net/library/file_sigs.html http://www.faqs.org/faqs/jpeg-faq/part1/section-15.html https://en.wikipedia.org/wiki/List_of_file_signatures

(Also, please consider moving log file from /tmp to vim.fn.stdpath('log'), i like them, they are useful)

3rd commented 7 months ago

Hi @Elvyria, thanks for the issue! I created a PR to fix this by mixing your first point with the last one, should be ok, right? https://github.com/3rd/image.nvim/pull/133

Elvyria commented 7 months ago

Yes, it works, thank you. Could you just please not open/close file twice and change read_file_header and has_jpeg_end_signature to accept file descriptor instead of a path (that should also save you some checks and lines of code)?

3rd commented 7 months ago

Done, thank you!