3rd / image.nvim

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

[ADD] Add SVG File preview support (maybe using `cairosvg`?) #177

Open MikeLemo1 opened 3 months ago

MikeLemo1 commented 3 months ago

I think I'd fine a good a idea to make the plugin more complete and add an ability to preview images maybe using the python module cairosvg (like how it is suggested they use it in the plugin benlubas/molten-nvim) in order to convert the SVG to png into a temp buffer and then let 3rd/image take over from there with the tricks it knows

That'd make the idea of an image previewer a little more complete.

maxencetholomier commented 3 months ago

Have you tried preview svg images ? It's working well on my config

maxencetholomier commented 3 months ago

There is opened issues related to this topic

MikeLemo1 commented 3 months ago

How? did you do it with the default config?

when I

a = require("image").from_file("my_image.svg")

it Error me:

E5108: Error executing lua ...ng/.local/share/nvim/lazy/image.nvim/lua/image/image.lua:300: attempt to index local 'magick_image' (a nil value)
stack traceback:
        ...ng/.local/share/nvim/lazy/image.nvim/lua/image/image.lua:300: in function 'from_file'
        [string ":lua"]:1: in main chunk

and no mention about SVG files in the 3rd/image/README.md

3rd commented 3 months ago

SVGs work fine for me as well, you're not getting any other kind of errors? Also does it work for you with other formats?

MikeLemo1 commented 3 months ago

Hi OK so I was playing around with svg(xml) file manipulation and generation and some of the test images I created do display something on libreDraw and now with vifm preview or 3rd/image and I notices it's when no viewBox is specified for a path shape element or when no width, height the image wont display in 3rd/image Maybe some mechanism of temporarly "injecting" parameters those based on calculated elements bounding box and some default screen preview pixel size

t1gu1 commented 2 months ago

If I open a .svg file directly in the buffer, no svg is displayed in the buffer.

nvim 0.11.0 MacOS m1

image

P.S. .png are displayed with the same manipulation.

3rd commented 2 months ago

We should add a flag for that, I think it's more common to want to edit the SVG as text than to view it.

t1gu1 commented 2 months ago

True! The crazy thing could be to be able to visualise the SVG under the last line of code while editing it and visualise the changes.

I never see a tool doing that. It could be a really nice selling point!

3rd commented 2 months ago

That's such a cool idea <3