fd4658434a
Import all built-in modules explicitly, remove dead ImageMagick branch, and call finalize_gmic_output in gmic_grayscale for resume parity with gmic. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from imagepipeline.core.context import ModuleContext
|
|
from imagepipeline.core.params import Param
|
|
from imagepipeline.modules.base import SubprocessModule
|
|
from imagepipeline.modules.registry import register
|
|
from imagepipeline.utils.gmic import finalize_gmic_output, split_gmic_command
|
|
from imagepipeline.utils.subprocess import run_command
|
|
|
|
|
|
@register
|
|
class GmicGrayscale(SubprocessModule):
|
|
name = "gmic_grayscale"
|
|
description = "Convert images to grayscale using G'MIC"
|
|
command_candidates = ("gmic",)
|
|
default_timeout = 300.0
|
|
|
|
@classmethod
|
|
def parameters(cls) -> dict[str, Param]:
|
|
return {
|
|
"command": Param(
|
|
"string",
|
|
default="-to_gray",
|
|
help="G'MIC command(s) applied before -output",
|
|
),
|
|
}
|
|
|
|
def run(self, ctx: ModuleContext) -> None:
|
|
ctx.output_dir.mkdir(parents=True, exist_ok=True)
|
|
gmic_command = ctx.params["command"]
|
|
total = len(ctx.input_paths)
|
|
|
|
for index, src in enumerate(ctx.input_paths, start=1):
|
|
self.log_image(ctx, index, total, src)
|
|
dst = ctx.output_dir / src.name
|
|
cmd = ["gmic", str(src), *split_gmic_command(gmic_command), "-output", str(dst)]
|
|
run_command(cmd, timeout=self.default_timeout)
|
|
finalize_gmic_output(ctx.output_dir, dst)
|