mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: respect the user's max_width setting for the built-in PDF preloader (#2331)
This commit is contained in:
parent
f506849fb5
commit
077faacc9a
1 changed files with 13 additions and 7 deletions
|
|
@ -30,17 +30,18 @@ function M:preload(job)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- stylua: ignore
|
||||||
local output, err = Command("pdftoppm")
|
local output, err = Command("pdftoppm")
|
||||||
:args({
|
:args({
|
||||||
|
"-f", job.skip + 1,
|
||||||
|
"-l", job.skip + 1,
|
||||||
"-singlefile",
|
"-singlefile",
|
||||||
"-jpeg",
|
"-jpeg", "-jpegopt", "quality=" .. PREVIEW.image_quality,
|
||||||
"-jpegopt",
|
"-tiffcompression", "jpeg",
|
||||||
"quality=" .. PREVIEW.image_quality,
|
"-scale-to-x", PREVIEW.max_width, "-scale-to-y", "-1",
|
||||||
"-f",
|
|
||||||
job.skip + 1,
|
|
||||||
tostring(job.file.url),
|
tostring(job.file.url),
|
||||||
|
tostring(cache),
|
||||||
})
|
})
|
||||||
:stdout(Command.PIPED)
|
|
||||||
:stderr(Command.PIPED)
|
:stderr(Command.PIPED)
|
||||||
:output()
|
:output()
|
||||||
|
|
||||||
|
|
@ -54,7 +55,12 @@ function M:preload(job)
|
||||||
return true, Err("Failed to convert PDF to image, stderr: %s", output.stderr)
|
return true, Err("Failed to convert PDF to image, stderr: %s", output.stderr)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue