Conditional arguments

This commit is contained in:
sxyazi 2025-03-26 19:06:11 +08:00
parent f2f837800e
commit 5306aad658
No known key found for this signature in database

View file

@ -24,23 +24,28 @@ function M:preload(job)
return true return true
end end
local cmd = Command("magick"):args { local cmd = Command("magick")
tostring(job.file.url), if job.args.flatten then
"-auto-orient", cmd = cmd:arg("-flatten")
"-strip", end
"-sample",
string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height),
"-flatten",
"-quality",
rt.preview.image_quality,
"JPG:" .. tostring(cache),
}
cmd = cmd:args { tostring(job.file.url), "-auto-orient", "-strip" }
if job.mime:find("/svg%+xml") then
cmd = cmd:args { "-density", 200 }
end
cmd = cmd:env("MAGICK_THREAD_LIMIT", 1)
if rt.tasks.image_alloc > 0 then if rt.tasks.image_alloc > 0 then
cmd = cmd:env("MAGICK_MEMORY_LIMIT", rt.tasks.image_alloc) cmd = cmd:env("MAGICK_MEMORY_LIMIT", rt.tasks.image_alloc)
end end
local status, err = cmd:env("MAGICK_THREAD_LIMIT", 1):status() -- stylua: ignore
local status, err = cmd:args {
"-sample", string.format("%dx%d>", rt.preview.max_width, rt.preview.max_height),
"-quality", rt.preview.image_quality,
string.format("JPG:%s", cache),
}:status()
if status then if status then
return status.success return status.success
else else