image.nvim icon indicating copy to clipboard operation
image.nvim copied to clipboard

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

Open MikeLemo1 opened this issue 1 year ago • 9 comments

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.

MikeLemo1 avatar Jun 07 '24 15:06 MikeLemo1

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

maxencetholomier avatar Jun 09 '24 11:06 maxencetholomier

There is opened issues related to this topic

maxencetholomier avatar Jun 09 '24 11:06 maxencetholomier

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

MikeLemo1 avatar Jun 09 '24 12:06 MikeLemo1

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?

3rd avatar Jun 09 '24 22:06 3rd

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

MikeLemo1 avatar Jun 10 '24 06:06 MikeLemo1

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.

t1gu1 avatar Jul 30 '24 00:07 t1gu1

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.

3rd avatar Jul 30 '24 16:07 3rd

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!

t1gu1 avatar Jul 30 '24 18:07 t1gu1

That's such a cool idea <3

3rd avatar Jul 31 '24 22:07 3rd