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

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

Open asfaltboy opened this issue 1 year ago • 2 comments

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.

asfaltboy avatar Sep 25 '24 21:09 asfaltboy

+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,
})

maxbol avatar Sep 29 '24 20:09 maxbol

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

3rd avatar Oct 02 '24 08:10 3rd

Hi, I created a PR for this. I wonder if this works?

https://github.com/3rd/image.nvim/pull/252

huntf-bitstrata avatar Nov 28 '24 21:11 huntf-bitstrata

@huntf-bitstrata thank you!

3rd avatar Dec 05 '24 00:12 3rd