mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: new --bg specifying image background color for the preset svg and magick previewers (#3189)
This commit is contained in:
parent
ba99ce4f8f
commit
8f9cce126c
2 changed files with 15 additions and 7 deletions
|
|
@ -31,13 +31,16 @@ function M:preload(job)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
local status, err = cmd:arg {
|
cmd = cmd:arg {
|
||||||
tostring(job.file.url), "-auto-orient", "-strip",
|
tostring(job.file.url), "-auto-orient", "-strip",
|
||||||
"-sample", string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height),
|
"-sample", string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height),
|
||||||
"-quality", rt.preview.image_quality,
|
"-quality", rt.preview.image_quality,
|
||||||
string.format("JPG:%s", cache),
|
}
|
||||||
}:status()
|
if job.args.bg then
|
||||||
|
cmd = cmd:arg { "-background", job.args.bg, "-alpha", "remove" }
|
||||||
|
end
|
||||||
|
|
||||||
|
local status, err = cmd:arg(string.format("JPG:%s", cache)):status()
|
||||||
if not status then
|
if not status then
|
||||||
return true, Err("Failed to start `magick`, error: %s", err)
|
return true, Err("Failed to start `magick`, error: %s", err)
|
||||||
elseif not status.success then
|
elseif not status.success then
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,25 @@ function M:preload(job)
|
||||||
local cmd = Command("resvg"):arg {
|
local cmd = Command("resvg"):arg {
|
||||||
"-w", rt.preview.max_width, "-h", rt.preview.max_height,
|
"-w", rt.preview.max_width, "-h", rt.preview.max_height,
|
||||||
"--image-rendering", "optimizeSpeed",
|
"--image-rendering", "optimizeSpeed",
|
||||||
tostring(job.file.url), tostring(cache)
|
|
||||||
}
|
}
|
||||||
|
if job.args.bg then
|
||||||
|
cmd = cmd:arg { "--background", job.args.bg }
|
||||||
|
end
|
||||||
if rt.tasks.image_alloc > 0 then
|
if rt.tasks.image_alloc > 0 then
|
||||||
cmd = cmd:memory(rt.tasks.image_alloc)
|
cmd = cmd:memory(rt.tasks.image_alloc)
|
||||||
end
|
end
|
||||||
|
|
||||||
local child, err = cmd:spawn()
|
local child, err = cmd:arg({ tostring(job.file.url), tostring(cache) }):spawn()
|
||||||
if not child then
|
if not child then
|
||||||
return true, Err("Failed to start `resvg`, error: %s", err)
|
return true, Err("Failed to start `resvg`, error: %s", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
local status, err
|
local status, err
|
||||||
while true do
|
if rt.tasks.image_alloc == 0 then
|
||||||
|
status, err = child:wait()
|
||||||
|
end
|
||||||
|
|
||||||
|
while not status and not err do
|
||||||
ya.sleep(0.2)
|
ya.sleep(0.2)
|
||||||
|
|
||||||
status, err = child:try_wait()
|
status, err = child:try_wait()
|
||||||
|
|
@ -56,7 +62,6 @@ function M:preload(job)
|
||||||
if mem and mem > rt.tasks.image_alloc then
|
if mem and mem > rt.tasks.image_alloc then
|
||||||
child:start_kill()
|
child:start_kill()
|
||||||
err = Err("memory limit exceeded, pid: %s, memory: %s", id, mem)
|
err = Err("memory limit exceeded, pid: %s, memory: %s", id, mem)
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue