From d4ae2df19f8ddbbbd65efd0d00f6e340b046f17c Mon Sep 17 00:00:00 2001 From: madmaxieee <76544194+madmaxieee@users.noreply.github.com> Date: Tue, 8 Sep 2026 15:11:13 +0800 Subject: [PATCH] fix(image): process png images through magick if available Ensure that image files are downscaled with ImageMagick when magick is available, even if the file extension is already png. --- lua/snacks/image/convert.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/snacks/image/convert.lua b/lua/snacks/image/convert.lua index e2aaa44e6..b20748276 100644 --- a/lua/snacks/image/convert.lua +++ b/lua/snacks/image/convert.lua @@ -202,6 +202,13 @@ local proc_queue = {} ---@type snacks.spawn.Proc[] local proc_running = 0 ---@type number local MAX_PROCS = 3 +local function has_magick() + if have.magick == nil then + have.magick = vim.fn.executable("magick") == 1 or (not Snacks.util.is_win and vim.fn.executable("convert") == 1) + end + return have.magick +end + ---@param proc? snacks.spawn.Proc local function schedule(proc) if proc then @@ -329,7 +336,7 @@ function Convert:resolve() self:_resolve("url") self:_resolve("identify") end - while self:ft() ~= "png" do + while self:ft() ~= "png" or (#self.steps == 0 and has_magick()) do local ft = self:ft() local target = commands[ft] and ft or "convert" if self:_resolve(target) then