fix: respect the user's image_alloc setting for the built-in ImageMagick previewer (#2403)

This commit is contained in:
三咲雅 · Misaki Masa 2025-02-26 20:47:11 +08:00 committed by sxyazi
parent 953d567c63
commit 950750f66e
No known key found for this signature in database
2 changed files with 29 additions and 16 deletions

View file

@ -24,22 +24,24 @@ function M:preload(job)
return true return true
end end
local status, err = Command("magick") local cmd = Command("magick"):args {
:args({ "-density",
"-density", 200,
200, tostring(job.file.url),
tostring(job.file.url), "-flatten",
"-flatten", "-resize",
"-resize", string.format("%dx%d^", rt.preview.max_width, rt.preview.max_height),
string.format("%dx%d^", rt.preview.max_width, rt.preview.max_height), "-quality",
"-quality", rt.preview.image_quality,
rt.preview.image_quality, "-auto-orient",
"-auto-orient", "JPG:" .. tostring(cache),
"JPG:" .. tostring(cache), }
})
:env("MAGICK_THREAD_LIMIT", 1)
:status()
if rt.tasks.image_alloc > 0 then
cmd = cmd:env("MAGICK_MEMORY_LIMIT", rt.tasks.image_alloc)
end
local status, err = cmd:env("MAGICK_THREAD_LIMIT", 1):status()
if status then if status then
return status.success return status.success
else else

View file

@ -1,6 +1,6 @@
use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value}; use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value};
use yazi_boot::ARGS; use yazi_boot::ARGS;
use yazi_config::{MGR, PREVIEW, THEME}; use yazi_config::{MGR, PREVIEW, TASKS, THEME};
use crate::{Composer, url::Url}; use crate::{Composer, url::Url};
@ -19,6 +19,7 @@ impl<'a> Runtime<'a> {
b"mgr" => Self::mgr(lua)?, b"mgr" => Self::mgr(lua)?,
b"plugin" => super::Plugin::compose(lua)?, b"plugin" => super::Plugin::compose(lua)?,
b"preview" => Self::preview(lua)?, b"preview" => Self::preview(lua)?,
b"tasks" => Self::tasks(lua)?,
_ => return Ok(Value::Nil), _ => return Ok(Value::Nil),
} }
.into_lua(lua) .into_lua(lua)
@ -62,6 +63,16 @@ impl<'a> Runtime<'a> {
}) })
} }
fn tasks(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 5, |lua, key| {
match key {
b"image_alloc" => lua.to_value_with(&TASKS.image_alloc, OPTS)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)
})
}
pub fn new(lua: &'a Lua) -> Self { Self { lua } } pub fn new(lua: &'a Lua) -> Self { Self { lua } }
// TODO: remove this // TODO: remove this