mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 00:01:03 +00:00
fix: respect the user's image_alloc setting for the built-in ImageMagick previewer (#2403)
This commit is contained in:
parent
953d567c63
commit
950750f66e
2 changed files with 29 additions and 16 deletions
|
|
@ -24,22 +24,24 @@ function M:preload(job)
|
|||
return true
|
||||
end
|
||||
|
||||
local status, err = Command("magick")
|
||||
:args({
|
||||
"-density",
|
||||
200,
|
||||
tostring(job.file.url),
|
||||
"-flatten",
|
||||
"-resize",
|
||||
string.format("%dx%d^", rt.preview.max_width, rt.preview.max_height),
|
||||
"-quality",
|
||||
rt.preview.image_quality,
|
||||
"-auto-orient",
|
||||
"JPG:" .. tostring(cache),
|
||||
})
|
||||
:env("MAGICK_THREAD_LIMIT", 1)
|
||||
:status()
|
||||
local cmd = Command("magick"):args {
|
||||
"-density",
|
||||
200,
|
||||
tostring(job.file.url),
|
||||
"-flatten",
|
||||
"-resize",
|
||||
string.format("%dx%d^", rt.preview.max_width, rt.preview.max_height),
|
||||
"-quality",
|
||||
rt.preview.image_quality,
|
||||
"-auto-orient",
|
||||
"JPG:" .. tostring(cache),
|
||||
}
|
||||
|
||||
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
|
||||
return status.success
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value};
|
||||
use yazi_boot::ARGS;
|
||||
use yazi_config::{MGR, PREVIEW, THEME};
|
||||
use yazi_config::{MGR, PREVIEW, TASKS, THEME};
|
||||
|
||||
use crate::{Composer, url::Url};
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ impl<'a> Runtime<'a> {
|
|||
b"mgr" => Self::mgr(lua)?,
|
||||
b"plugin" => super::Plugin::compose(lua)?,
|
||||
b"preview" => Self::preview(lua)?,
|
||||
b"tasks" => Self::tasks(lua)?,
|
||||
_ => return Ok(Value::Nil),
|
||||
}
|
||||
.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 } }
|
||||
|
||||
// TODO: remove this
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue