3rd / image.nvim

🖼️ Bringing images to Neovim.
MIT License
1.15k stars 50 forks source link

Allow controlling "zoom" level, to proportionally increase image size #220

Open asfaltboy opened 1 month ago

asfaltboy commented 1 month ago

Some images may look small, especially on screens with high DPI (e.g retina). So it would be cool to control the image size by allowing one to zoom in.

maxbol commented 1 month ago

+1 for this!

I did my own little solution for this, it more or less works, but with some unexpected behaviors. Give it a try!

local autocmd = vim.api.nvim_create_autocmd
local map = vim.keymap.set

autocmd("BufRead", {
  group = "image.nvim",
  callback = function(o)
    local bufnr = o.buf
    local images = image.get_images({ buffer = bufnr })
    if #images ~= 1 then
      return
    end

    local preview_image = images[1]

    map("n", "+", function()
      preview_image.image_width = preview_image.image_width * 1.25
      preview_image.image_height = preview_image.image_height * 1.25
      preview_image:render()
    end, {
      buffer = bufnr,
      desc = "Zoom in image",
    })

    map("n", "_", function()
      preview_image.image_width = preview_image.image_width / 1.25
      preview_image.image_height = preview_image.image_height / 1.25
      preview_image:render()
    end, {
      buffer = bufnr,
      desc = "Zoom out image",
    })
  end,
})
3rd commented 1 month ago

Ha that's cool, we'll add a global scaling option as well!