feat: respect the user's max_width setting for the built-in PDF preloader (#2331)

This commit is contained in:
三咲雅 · Misaki Masa 2025-02-13 19:02:17 +08:00 committed by GitHub
parent f506849fb5
commit 077faacc9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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