From 077faacc9a84bb5a06c5a8185a71405b0cb3dc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Thu, 13 Feb 2025 19:02:17 +0800 Subject: [PATCH] feat: respect the user's `max_width` setting for the built-in PDF preloader (#2331) --- yazi-plugin/preset/plugins/pdf.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/yazi-plugin/preset/plugins/pdf.lua b/yazi-plugin/preset/plugins/pdf.lua index 5ecf43da..357f3a09 100644 --- a/yazi-plugin/preset/plugins/pdf.lua +++ b/yazi-plugin/preset/plugins/pdf.lua @@ -30,17 +30,18 @@ function M:preload(job) return true end + -- stylua: ignore local output, err = Command("pdftoppm") :args({ + "-f", job.skip + 1, + "-l", job.skip + 1, "-singlefile", - "-jpeg", - "-jpegopt", - "quality=" .. PREVIEW.image_quality, - "-f", - job.skip + 1, + "-jpeg", "-jpegopt", "quality=" .. PREVIEW.image_quality, + "-tiffcompression", "jpeg", + "-scale-to-x", PREVIEW.max_width, "-scale-to-y", "-1", tostring(job.file.url), + tostring(cache), }) - :stdout(Command.PIPED) :stderr(Command.PIPED) :output() @@ -54,7 +55,12 @@ function M:preload(job) return true, Err("Failed to convert PDF to image, stderr: %s", output.stderr) end - return fs.write(cache, output.stdout) + local ok, err = os.rename(string.format("%s.jpg", cache), tostring(cache)) + if ok then + return true + else + return false, Err("Failed to rename `%s.jpg` to `%s`, error: %s", cache, cache, err) + end end return M