为什么 GIMP 脚本不能在 CLI 模式下运行?
Why doesn't work the GIMP-script in CLI mode?
我写了一个 GIMP 脚本,如果我通过 GIMP-GUI 中的按钮打开它,它可以工作,但如果我尝试在 CLI 模式(在 Ubuntu 上)启动它,它就不起作用。
我尝试了以下命令:
gimp -c -i -d -b '(documentEnhancementProcedure 1 "raw.png" "test.png")' -b '(gimp-quit 0)'
并得到错误:“file-png-load 的参数 2 的类型无效”。
由于脚本有效,当我从 GIMP-GUI 启动它时,我认为这是 CLI 命令的问题。
我试过:
- 完整文件路径
- 转义字符
我认为这可能是一个小错误,但我目前无法发现它...
提前感谢您的帮助!
脚本:
(define (documentEnhancementProcedure infile outfile)
(let*
(
(image (car (file-png-load 1 infile infile)))
(drawable (car (gimp-image-get-active-drawable image)))
(image-width (car (gimp-image-width image)))
(image-height (car (gimp-image-height image)))
)
;1. scale image by the factor 2
(gimp-image-scale image
(* image-width 2) (* image-height 2))
; (* image-width 2) New image width (1 <= new-width <= 524288)
; (* image-height 2) New image height (1 <= new-height <= 524288)
;2 apply sharpen-filter with given variables
(plug-in-unsharp-mask 1 image drawable
3 0.4 0)
; 3 Radius of gaussian blur (0 <= radius <= 300)
; 0.4 Strength of effect (0 <= amount <= 300)
; 0 Threshold (0 <= threshold <= 255)
;3.save image as png
(file-png-save2 1 image drawable outfile outfile
1 0 0 0 0 0 0 0 0 )
; 1 Adam7 interlacing?
; 0 deflate compression factor (0-9)
; 0 Write bKGD chunk?
; 0 Write gAMMA chunk?
; 0 Write oFFs chunk?
; 0 Write pHYS chunk?
; 0 Write tIME chunk?
; 0 Write comment?
; 0 Preserve color of transparent pixels?
)
)
(script-fu-register
"documentEnhancementProcedure" ; script name to register
"<Toolbox>/Xtns/Script-Fu/ownScripts/documentEnhancementProcedure" ; where it goes
"document gets doubeld in size\
and sharpened with following sharpen variables:\
radius 3\
amount 0.4\
threshold 0" ; script description
"" ; author
"Copyright 2021 by; GNU GPLv3" ; copyright
"23.09.2021" ; date
"" ; type of image
SF-FILENAME "Infile" "infile.png" ; default parameters
SF-FILENAME "Outfile" "outfile.png"
)
by @xenoid 有效:
Try omitting the RUN-MODE
argument. Btw, 1) you don't need to register the script if you use it in batch mode, and 2) you can do the very same thing in one line using ImageMagick's convert
command (see -geometry
and -sharpen
args).
我写了一个 GIMP 脚本,如果我通过 GIMP-GUI 中的按钮打开它,它可以工作,但如果我尝试在 CLI 模式(在 Ubuntu 上)启动它,它就不起作用。 我尝试了以下命令:
gimp -c -i -d -b '(documentEnhancementProcedure 1 "raw.png" "test.png")' -b '(gimp-quit 0)'
并得到错误:“file-png-load 的参数 2 的类型无效”。
由于脚本有效,当我从 GIMP-GUI 启动它时,我认为这是 CLI 命令的问题。
我试过:
- 完整文件路径
- 转义字符
我认为这可能是一个小错误,但我目前无法发现它...
提前感谢您的帮助!
脚本:
(define (documentEnhancementProcedure infile outfile)
(let*
(
(image (car (file-png-load 1 infile infile)))
(drawable (car (gimp-image-get-active-drawable image)))
(image-width (car (gimp-image-width image)))
(image-height (car (gimp-image-height image)))
)
;1. scale image by the factor 2
(gimp-image-scale image
(* image-width 2) (* image-height 2))
; (* image-width 2) New image width (1 <= new-width <= 524288)
; (* image-height 2) New image height (1 <= new-height <= 524288)
;2 apply sharpen-filter with given variables
(plug-in-unsharp-mask 1 image drawable
3 0.4 0)
; 3 Radius of gaussian blur (0 <= radius <= 300)
; 0.4 Strength of effect (0 <= amount <= 300)
; 0 Threshold (0 <= threshold <= 255)
;3.save image as png
(file-png-save2 1 image drawable outfile outfile
1 0 0 0 0 0 0 0 0 )
; 1 Adam7 interlacing?
; 0 deflate compression factor (0-9)
; 0 Write bKGD chunk?
; 0 Write gAMMA chunk?
; 0 Write oFFs chunk?
; 0 Write pHYS chunk?
; 0 Write tIME chunk?
; 0 Write comment?
; 0 Preserve color of transparent pixels?
)
)
(script-fu-register
"documentEnhancementProcedure" ; script name to register
"<Toolbox>/Xtns/Script-Fu/ownScripts/documentEnhancementProcedure" ; where it goes
"document gets doubeld in size\
and sharpened with following sharpen variables:\
radius 3\
amount 0.4\
threshold 0" ; script description
"" ; author
"Copyright 2021 by; GNU GPLv3" ; copyright
"23.09.2021" ; date
"" ; type of image
SF-FILENAME "Infile" "infile.png" ; default parameters
SF-FILENAME "Outfile" "outfile.png"
)
Try omitting the
RUN-MODE
argument. Btw, 1) you don't need to register the script if you use it in batch mode, and 2) you can do the very same thing in one line using ImageMagick'sconvert
command (see-geometry
and-sharpen
args).