3rd / image.nvim Goto Github PK
View Code? Open in Web Editor NEW๐ผ๏ธ Bringing images to Neovim.
License: MIT License
๐ผ๏ธ Bringing images to Neovim.
License: MIT License
It seems like iterm2 over SSH is not working even with ueberzugpp ( I did not test it in local, but it would not work well )
I fixed the problem by changing two lines in ueberzug.lua
This fix works in tmux over SSH.
6 M lua/image/backends/ueberzug.lua
7 @@ -5,12 +5,12 @@ local should_be_alive = false
8
9 local spawn = function()
10 local stdin = vim.loop.new_pipe()
11 - local stdout = vim.loop.new_pipe()
12 + local stdout = vim.loop.new_tty(1, false)
13 local stderr = vim.loop.new_pipe()
14 should_be_alive = true
15
16 local handle, pid = vim.loop.spawn("ueberzug", {
17 - args = { "layer", "--silent" },
18 + args = { "layer", "--silent", "-o", "iterm2" },
19 stdio = { stdin, stdout, stderr },
20 }, function(code, signal)
21 child = nil
I did not test it well, leaving this as an issue.
Commit 1e0a270 changes the base64 encode string "/" into "-". I'm wondering what this purpose is? I'm not super familiar with base64 but my understanding is the "/" is standard in the b64 alphabet.
I've been looking into how I setup direct-mode in kitty to allow for images to be displayed over a remote connection/ssh and reverting this allows this the images to be displayed. Does this somehow effect operation in file mode?
When having fairly large images (e.g. different sizes of https://www.pexels.com/photo/scenic-view-of-mountains-during-dawn-1261728/) in a markdown document, nvim blocks when the cursor reaches the image line to process the image.
This could be improved by running the processing async such that one could still scroll over the image and by caching the result such that the processing doesn't have to happen again when the cursor reaches the line a second time.
First of all amazing work, I plan to use it in my day to day but I would like to know how to set a maximum size
For NixOS user using home-manager, magick can be installed in extraLuaPackages as follows. I think this is much simpler.
programs.neovim = {
enable = true;
package = pkgs.neovim-nightly;
extraLuaPackages = ps: [
ps.magick
];
};
It's possible to render an image at the bottom of the screen that escapes into the rest of the terminal (that grey bar is the tmux bar).
It would be nice for image.nvim
to be able to automatically crop images that are going to display outside of NeoVim. It would also be amazing if there was an option to autocrop images that would display over the status bar.
If I add an image link in a markdown file, often the image doesn't appear until I load another file, and then go back to the original file.
The same happens when I delete an image link (the image doesn't disappear), but not if it's the last image link I added to the file.
(Version c91d47c)
Here is a rendered image with a window and buffer specified, and it has a position of x=0, y=1
(with 0 indexed rows). It displays fine in a window without borders, but the window relative positioning doesn't seem to account for borders, and it just draws the image over them.
I'm happy to submit a PR for this. I just want to check weather or not this is something you think image.nvim
should handle, or if this is up to users to deal with. Personally I'd vote for respect window boarders as an on by default render option.
Hi, sorry for spamming you with feature requests lol.
While doing the integration to neo-tree I needed to detect the buffers that the images where loaded in.
And I would like to propose two feature requests regarding this issue.
vim.bo[buf].filetype
to something plugin specific.If you can set a filetype to the buffer on BufRead
, it would be much easier to render the preview.
local buf = ...
vim.bo[buf].filetype = "image_nvim" -- or "image_nvim_png" etc would be nice too if possible
It would be nice if I can call the hijack buffer code (basically the callback of the current autocmd) from outside as an API.
---@param path string
---@param win number? if nil or 0, uses current window
---@param buf number? if nil or 0, uses current buffer
---@param options ImageOptions?
api.hijack_buffer = function(path, win, buf, options)
if not win or win == 0 then win = vim.api.nvim_get_current_win() end
if not buf or buf == 0 then buf = vim.api.nvim_get_current_buf() end
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, 0, -1, true, { "" })
vim.bo[buf].modifiable = false
vim.bo[buf].buftype = "nowrite"
vim.opt_local.colorcolumn = "0"
vim.opt_local.cursorline = false
vim.opt_local.number = false
vim.opt_local.signcolumn = "no"
-- vim.bo[buf].filetype = ...
options = options or {}
options.window = win
options.buffer = buf
local img = api.from_file(path, options)
img:render()
return img
end
Thanks in advance.
The call to magick.load_image()
in lua/image/image.lua
at line 265 can return nil
which causes error at line 268 every time the text being changed inside current buffer:
image.nvim/lua/image/image.lua
Line 265 in 6598813
Firstly thank you for your work on this plugin, especially for the Neorg integration.
I was curious about Konsole support, I was under the impression that Konsole is making use of the same protocols as Kitty, the "Terminal graphics protocol" but when I use Konsole the image is invisible. The box shows up, the spacing is there as if an image was rendered, if I make a new line the line is placed under where an image would be but there is no image rendered.
Not sure if this is a bug or if Konsole requires additional support. Hope you perhaps consider this regardless. Thanks
Here I have an image rendering with the markdown integration in the buffer. I have these two options set in my config:
window_overlap_clear_enabled = true, -- toggles images when windows are overlapped
window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
and the molten output window here does have a filetype, so it should cause the image to disappear if the two overlap.
My issue is that this output window wouldn't overlap the image if it didn't disappear, and in some cases never overlaps the area that was occupied by the image, so I don't think the image should be disappearing here.
My first guess would be, make sure we're checking against the rendered geometry instead of the full image size. But I'll look into this more tomorrow.
os: Arch linux
terminal: foot
backend: ueberzug
with minimal config the place holder comes but no image is previewed
below is my config
-- Example for configuring Neovim to load user-installed installed Lua rocks:
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"
local istatus, image = pcall(require, "image")
if not istatus then
return
end
image.setup({
backend = "ueberzug",
integrations = {
markdown = {
enabled = true,
sizing_strategy = "auto",
download_remote_images = true,
clear_in_insert_mode = false,
},
neorg = {
enabled = true,
download_remote_images = true,
clear_in_insert_mode = false,
},
},
max_width = nil,
max_height = nil,
max_width_window_percentage = nil,
max_height_window_percentage = 50,
kitty_method = "normal",
kitty_tmux_write_delay = 10, -- makes rendering more reliable with Kitty+Tmux
window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
})```
`luarocks --local --lua-version=5.1 install magick` used this command to install magick
and have `ueberzugpp` from aur
and imagemagick from arch repos
Hello and thanks for this, for the first time we are getting real images integration into Neovim !
I don't know if it's a bug of my own since it is not specified anywhere, but when opening md/norg files in neovim from tmux, the images are exactly as it should be in the files. But they also spawn into every tmux panes as a background also.
I have the last kitty/neovim/tmux versions with default setup for image.nvim and enabling the passthrough in tmux with "set -g allow-passthrough on"
I use comment.nvim to comment code with a keybind. This uses treesitter to determine the correct comment string to use for files like markdown, where you could be in a code block, and need a different comment string.
I have no idea why, but enabling the markdown integration breaks this dynamic comment string functionality. So in a markdown file it would only even comment with html style comments, even in code blocks.
This only affects nightly
Originally posted by niksingh710 August 31, 2023
is it possible to only render image when cursor is over path of the image as this will make ueberzug one faster?
Thanks a ton for this amazing plugin, already seems way more stable/reliable than what was before
NVIM v0.10.0-dev-429+g9f3c4c152-dirty + MacOS Ventura 13.4 M1 Max MBP + Kitty 0.28.1
Right now, images will just overlap with e.g. telescope or nvim-cmp.
Also, likely unrelated:
on the large image piece - this is often very much unintentionally large but these are images that are much smaller in the markdown. Maybe would be helpful to be able to define a default size that everything gets resized to? would work for many of my use cases
Thanks a ton for your hard work here ๐
Hey, I think you could add your nice plugin to luarocks so we can just luarocks install
it alongside to its dependencies. You can use this awesome tool to automate almost the whole process for you (even creating the rockspec file iirc) :)
Cheers!
When adding treesitter folds and a statusline with cmdheight 0 to the minimal config (https://github.com/3rd/image.nvim?tab=readme-ov-file#try-it-out-with-a-minimal-setup)
-- add folds with treesitter grammar
vim.opt.foldmethod = "expr"
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
-- but open all by default
vim.opt.foldlevel = 99
vim.opt.cmdheight = 0
I get a flickering statusline that is most apparent when in visual mode.
I am using POP OS, kitty, latest neovim nightly appimage
I installed magick with luarocks --local --lua-version=5.1 install magick
, but when I try to run nvim --clean -c ":luafile minimal-setup.lua"
, I get
Error detected while processing User Autocommands for "VeryLazy":
image.nvim: magick rock not found, please install it and restart your editor
I'm not sure why, I checked and magick is indeed in ~/.luarocks/share/lua/5.1
, maybe it's because the default installed lua is 5.3?
Not sure how to get meaningful logs but I'm able to reproduce a crash after scrolling up/down and toggling fullscreen in succession.
kitty: 0.29.0
neovim: v0.9.1
image.nvim: 24c3121
I cannot get image.nvim to respect options for width and height in image geometry. All attempts result in the image shrinking to a single character unit in width and height. I would expect it to snap to the closest multiple of the character unit (although it would be nice if more snapping options were available, like only snapping on one axis).
...
local geometry = { x = 0, y = 0, width = 1000, height = 1000 } -- no size works
local symbol = image.from_file("/home/user/image.png", {})
symbol:render(geometry)
Hi! Awesome plugin. Do you think there is a way to use this to render images on the statusline?
I've been looking for a way to have something like emacs's nyan-mode in neovim for a while now
and this plugin gives me hope.
Kitty terminal, using kitty graphics. This is in a markdown file with 5 images rendering at the same time, but it happens with only one image as well.
maybe a mild seizure warning.
After trying this with only one image, it seems like it's due to the issue of extmarks belonging to a buffer, and when the buffer is scrolled, they're removed from the scrolled buffer, added back in the non-scrolled buffer, and removed and added and removed and added over and over again.
Hi, first of all, thanks for making this great plugin!
I'm excited to test it out with ueberzug backend on alacritty, but as shown in the screen recording the rendering speed is so slow that I can hardly move my cursor around and scroll the window. There's also a lot flickering.
Would be great if there was documentation on how this project compares to hologram.nvim. For example, does it fix any of the display issues present in the original?
Hi, thanks again for implementing the image preview feature for png
etc files.
Please forgive me if I'm wrong, but as I was testing your code I think we need more events than only BufRead
to work properly.
For example, when calling :vsplit
, the image does not appear on the second window.
I guess we should use { "BufRead", "BufWinEnter" }
to make this work?
To be exact, I believe this issue comes from the code below, where has_valid_filetype
does not take options.hijack_file_patterns
into account. But in real world, since the image buffer cannot be modified, we don't need for example CursorMoved, Insert*
, nor opened as a new empty buffer (BufNew
etc), which results in covering all cases with just BufRead, BufWinEnter
?
image.nvim/lua/image/utils/document.lua
Lines 130 to 186 in 1cb60be
Another mild seizure warning.
Here, I have an image that renders in a floating window, and that floating window is shown only when the cursor is in the code cell here. I've setup a macro that presses kj
to enter the cell (making the window with an image show) and then leave it immediately. I then execute that macro 50 times, and this causes images to hang around after the window is closed.
Interestingly, I see different behavior when I'm in tmux. In tmux only occasionally do I see "ghost characters" that get drawn instead of staying behind the scenes as image protocol commands. These chars go away when I move my cursor over the line they're on.
I'm not concerned about getting this fixed at all. I highly doubt that anyone would encounter this unless they were intentionally trying to do it (at least, I can't get it to happen in normal use) but perhaps someone on older hardware or a system under load would encounter this.
I'm on MacOS on apple silicon (unsure if that's relevant)
I've installed the magick rock with luarocks --local --lua-version 5.1 install magick
I added
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua;"
to my nvim/init.lua
file, and I've checked that the magick folder exists at ~/.luarocks/share/lua/5.1/magick
However, I don't have anything other than the magick/
folder in the ~/.luarocks/share/lua/5.1/
directory. This concerns me b/c it seems from the package.path
code above that there should be a lua file there (but I have no idea).
I have ImageMagic via brew, the which magick
=> /opt/homebrew/bin/magick
Despite all of this, I still get this error when I launch nvim:
Error detected while processing /Users/benlubas/github/.dotfiles/nvim/init.lua:
image.nvim: magick rock not found, please install it and restart your editor
I've also tried with both nvim 9.2, and the latest nightly. same error.
I've also tried the minimial-setup.lua
file in this repo.
Environment:
kitty 0.29.2
+ tmux 3.3a
(with allow-passthrough on)NVIM v0.10.0-dev-1334+gd2d38858d1
1cb60be1cdc108e3a3b09cb0ed115ef75ce51320
Linux 6.1.58-1-lts
Minimal plugin config:
require('image').setup({
backend = 'kitty',
window_overlap_clear_enabled = true,
tmux_show_only_in_active_window = true,
})
Steps to reproduce:
Open kitty terminal
Execute tmux
Using nvim with image.nvim installed and configured to open a markdown file with contents
![ConvExample](https://stanford.edu/~shervine/teaching/cs-230/illustrations/convolution-layer-a.png?1c517e00cb8d709baf32fc3d39ebae67)
For a convolutional operation, the stride
**S** denotes the number of pixels by which the window moves after each operation.
![StrideExample](https://stanford.edu/~shervine/teaching/cs-230/illustrations/stride.png?36b5b2e02f7e02c3c4075a9d836c048c)
Split current tmux window horizontally or vertically
Images get misplaced
Screenshots:
see the gif for what I mean. I haven't looked at the code, but I would guess this has something to do with the way the markdown integration keeps track of images.
It seems like when moving an image to a new line, it's considered a new image and the data has to be sent to the terminal again (which takes a significant amount of time for larger image).
This issue is just to document the problem. I'd imagine it would also affect the neorg integration
Hi, introduced by the neorg community, I'm having a wonderful time with your plugin!
I was wondering if this plugin could be extended to visualizing png
, jpg
etc images.
When opening images inside neovim, currently it just displays binary junk but it would be awesome if this plugin could hijack the buffer and display the actual image.
I found this plugin: https://github.com/samodostal/image.nvim which uses ascii chars to do something similar.
I would love to hear your opinion. Thanks in advance.
After some exploration I found another issue that after switching tmux window the image in the previous window is not cleared.
Here is a short screen recording that demonstrate it:
Environment:
kitty 0.29.2
+ tmux 3.3a
(with allow-passthrough
on)NVIM v0.10.0-dev-1334+gd2d38858d1
1cb60be1cdc108e3a3b09cb0ed115ef75ce51320
Linux 6.1.58-1-lts
Plugin config:
package.path = table.concat(
{
package.path,
vim.fs.normalize('~/.luarocks/share/lua/5.1/?/init.lua'),
vim.fs.normalize('~/.luarocks/share/lua/5.1/?.lua'),
},
';'
)
require('image').setup({
window_overlap_clear_enabled = true
})
Originally posted by benlubas October 9, 2023
I just have a question about the way cropping works when an image is too big to fit where it's placed.
I feel like I've seen two behaviors:
number two is the behavior that I've seen more recently, and I'm wondering what has changed, is that a kitty thing? or something that the plugin is doing? I see that the kitty backend in this plugin has the "crop" feature, so I'm guessing that this is something kitty is doing, and the other behavior was the way image magick was cropping images.
I do prefer behavior 1, where it just shows part of the image and I have to scroll to see the rest. Is there currently a way to configure the plugin to use that behavior with kitty?
Trying to reference a video file, from a markdown link, shouldn't attempt render.
Expected behaviour: display link without attempting render.
Actual behaviour: image.nvim attempts render and then crashes.
Workaround: remove file extension from file avoids the issue.
Tested on Nobara 38, on minimal-setup.lua
I think this, or something similar, would make a good addition to the API. I've come across a situation where I'd like to know the rendered size of an image (accounting for user settings) before I actually render it.
Given that all the information this function needs is exposed to the user in some way or another before render is called, I could just duplicate this logic in my own plugin. But then if this logic changes (which it may, given that it currently squishes images to align to the terminal grid) then I (and potentially others) would need to change things.
This change could be as simple as adding the function to the return statement in renderer.lua
, or we could potentially make a nicer function on image itself that calculates the same information, such as img:rendered_size()
without needing to take a bunch of arguments.
Thoughts?
Hi. Thank you for your wonderful plugin.
Can you add a option to disable integration's autocommand setup and expose integrations's render(not image's render)? In this way, users can control the timing of render by themselves.
For example, I want to use the shortcut key to trigger whether to display the images under this file or cursor.
one of the changes in 440aee9 made it so that images in floating windows flash rapidly. It happens with the latest version of master as well. I see this on nightly and stable versions of neovim
As I remember earlier sixel was mentioned in README for future but now I guess it is removed.?
Continuing conversation from #20.
To recap, the current implementation forces images to alight with the grid. So let's say you have a grid size of 5px wide by 10px tall. and an image that is 5px by 14px, the image would be displayed as a 5px by 10px image, as it's forced to align with the cell. This effect becomes less and less noticeable as images get larger, but it's still been very noticeable for me in regular use.
It would be great if we could just not force the image into the terminal grid. So if an image was (like in the example from above) 4px taller than a cell, it would take up an extra vertical cell, but only use 4 pixels of it.
I'm not too familiar with image protocols, but I'd imagine they're able to do this by just padding the edge of an image with transparent pixels.
In the renderer, we crush the image down to max_width
and max_height
before fixing the aspect ratio. In fixing the aspect ratio, we then ignore the max width/height allowing one of the max values to be exceeded.
This problem I think is made worse by choosing to keep the larger of the width and height and adjust the smaller value? Just fixing this issue made the max_width/height
values behave pretty much how I expected them to, although I know there are edge cases that need a more thorough solution.
I think that more thorough solution would be to keep the value that gets reduced the most. This way the other value with always shrink, and therefore cannot exceed it's max value.
I'm happy to submit a PR if the things that I'm saying make sense.
Firstly, thanks for you effort on this amazing plugin!
A small bug I found when playing with it is that when &wrap
is set and there is a wrapped long line before the image, the image position will be miscalculated, here are some screenshots:
No wrap:
After :set wrap
:
Could we take &wrap
into consideration when calculating the image position? In addition, some options, such as &soothscroll
, &breakindent
, &breakindentpot
, &linebreak
can affect the visual height of a single logic line.
Hi, super exciting to see some progress on the images-in-vim front! This is something I've been wanting for quite some time now. I installed and tried it out, but no matter what I do I can't seem to get the images to show up.
Some things I've tried:
magick
rock is installed and in my rtpkitty +kitten icat <image>
does show the image in the terminalnvim --clean -c ":luafile minimal-setup.lua"
I created a minimal repro config file
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- Add luarocks to rtp
local home = vim.loop.os_homedir()
package.path = package.path .. ";" .. home .. "/.luarocks/share/lua/5.1/?/init.lua;"
package.path = package.path .. ";" .. home .. "/.luarocks/share/lua/5.1/?.lua;"
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{ "3rd/image.nvim", opts = {} },
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {
"markdown",
"markdown_inline",
},
})
end,
},
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
And if I run it with nvim -u repro.lua
on the test file
# Hello World
![This is a remote image](https://gist.ro/s/remote.png)
it reproduces the issue. No images.
Any ideas what's going on?
I use nvim --clean -c ":luafile minimal-setup.lua"
to test:
Is this expected behavior?
I'm using a tiling wm. So, for example when i open a new app and kitty resizes, the images in the buffer just dissappear. In place of them is just blank space. Is there a way of fixing this issue? Thanks!
Hi!
I just wanted to offer a suggested for a different backend to add. https://github.com/dankamongmen/notcurses
It seems to have good support for a wide variety of terminals. I'm not sure how active it is anymore, but it seems to be a very complete library as of now.
I don't know how feasible this would be (I haven't done too much neovim/lua dev), but I saw that ImageMagick has gif based functions. Would adding gif support be in the scope of this project? If this isn't, I'll see if I can get it working just by rendering each frame individually.
Would be cool if this repository had a license. MIT would be nice similar to hologram.nvim.
The original lua magic module was deprecated and can not be installed with luarocks. New version is renamed to libmagic
and can be found here
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.