; dmmPNGtoGrayscale - GIMP Script-Fu to convert a PNG image to Grayscale
; This Script-Fu must be put in The GIMP's script directory
; (e.g., $HOME/.gimp-1.2/scripts).
; For command-line invocation, use the shell script rgbtogs.sh
; For interactive invocation, run The GIMP and go to
; Xtns -> Script-Fu -> dmm
;
(define (dmmPNGtoGrayscale infile outfile)
(let* ((image (car (file-png-load 1 infile infile)))
(drawable (car (gimp-image-active-drawable image)))
)
(gimp-convert-grayscale image)
(file-png-save 1 image drawable outfile outfile
1 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 tIME chunk? ?? backwards in DB Browser
; 0 Write pHYS chunk? ?? backwards in DB Browser
)
)
(script-fu-register ; I always forget these ...
"dmmPNGtoGrayscale" ; script name to register
"<Toolbox>/Xtns/Script-Fu/dmm/dmmPNGtoGrayscale" ; where it goes
"dmm PNG (RGB or Indexed) to Grayscale" ; script description
"David M. MacMillan" ; author
"Copyright 2004 by David M. MacMillan; GNU GPL" ; copyright
"2004-02-08" ; date
"" ; type of image
SF-FILENAME "Infile" "infile.png" ; default parameters
SF-FILENAME "Outfile" "outfile.png"
)
并使用此脚本启动它(rgbtogs.sh例如,我将其命名):
# rgbtogs.sh
# Invoke The GIMP with Script-Fu dmmPNGtoGrayscale.scm
# No error checking.
if [ -e $1 ]
then
echo "Usage: rgbtogs.sh degrees filebasename"
echo "Error: Parameter (filename base) required"
exit 1
fi
gimp -c -i -d -b "(dmmPNGtoGrayscale \"$1.png\" \"$1-gray.png\")" "(gimp-quit 0)"
; dmmConvertPNGtoJPG.scm - GIMP Script-Fu to Convert PNG to JPG
; This Script-Fu must be put in The GIMP's script directory
; (e.g., $HOME/.gimp-1.2/scripts).
; For command-line invocation, use the shell script pngtojpg.sh
; For interactive invocation, run The GIMP and go to
; Xtns -> Script-Fu -> dmm
;
(define (dmmConvertPNGtoJPG infile outfile)
(let* ((image (car (file-png-load 1 infile infile)))
(drawable (car (gimp-image-active-drawable image)))
)
(file-jpeg-save 1 image drawable outfile outfile
0.75 0 1 1 "GIMP" 0 1 0 0 )
; 0.75 quality (float 0 <= x <= 1)
; 0 smoothing factor (0 <= x <= 1)
; 1 optimization of entropy encoding parameter (0/1)
; 1 enable progressive jpeg image loading (0/1)
; "xxxx" image comment
; 0 subsampling option number
; 1 force creation of a baseline JPEG
; 0 frequency of restart markers
; in rows, 0 = no restart markers
; 0 DCT algoritm to use
)
)
(script-fu-register ; I always forget these ...
"dmmConvertPNGtoJPG" ; script name to register
"<Toolbox>/Xtns/Script-Fu/dmm/dmmConvertPNGtoJPG" ; where it goes
"dmm Convert PNG to JPG" ; script description
"David M. MacMillan" ; author
"Copyright 2004 by David M. MacMillan; GNU GPL" ; copyright
"2004-01-27" ; date
"" ; type of image
SF-FILENAME "Infile" "infile.png" ; default parameters
SF-FILENAME "Outfile" "outfile.png"
)
并使用此脚本启动它(pngtojpg.sh例如,我将其命名):
# pngtojpg.sh
# Invoke The GIMP with Script-Fu dmmConvertPNGtoJPG.scm
# No error checking.
if [ -e $1 ]
then
echo "Usage: pngtojpg.sh filebasename"
echo "Error: Parameter 1 (filename base) required"
exit 1
fi
gimp -c -i -d -b "(dmmConvertPNGtoJPG \"$1.png\" \"$1.jpg\")" "(gimp-quit 0)"
我不知道如何使用 Gimp 来完成这项任务,但实际上我认为包
imagemagick
中的工具是此类 CLI 任务的更好选择。该软件包被广泛用作 Web 服务器应用程序(如 MediaWiki 和 WordPress)的转换工具,同时它也是 PhotoShop 等图形应用程序执行的一些操作的后端。首先你需要安装包:然后使用以下命令完成任务(参考):
如果您需要转换当前目录中的所有 PNG 文件,可以使用如下循环:
打开图片真的很简单(
image.png
就是你要打开的图片)将 RGB 图像转换为灰度:
创建一个 GIMP Script-Fu 文件(在此处命名
dmmConvertPNGtoGrayscale.scm
并保存在 中$HOME/.gimp-2.8/scripts
):并使用此脚本启动它(
rgbtogs.sh
例如,我将其命名):执行脚本并启动它:
将 PNG 图像转换为 JPEG(或 JPG):
创建一个 GIMP Script-Fu 文件(在此处命名
dmmConvertPNGtoJPG.scm
并保存在 中$HOME/.gimp-2.8/scripts
):并使用此脚本启动它(
pngtojpg.sh
例如,我将其命名):执行脚本并启动它:
来源:http ://beefchunk.com/documentation/lang/gimp/GIMP-Scripts-Fu.html
注意:在 GIMP Script-Fu 文件中,您可以删除所有以字符开头的行
;
(或该字符右侧的所有内容),这些只是注释注意:这些
.scm
script-fu 最初是为 GIMP 1.2 制作的,但我用 GIMP 2.8 测试过,没有问题您可以运行
gimp -h
以获取 gimp 可用的不同选项1.打开一张图片
gimp -n image_name.xxx
2.将图像转换为灰度我不知道是否可以使用 Gimp 导航这些链接:https ://www.gimp.org/tutorials/Basic_Batch/
https://superuser.com/questions/1334386/how-to-load-an-image-in-gimp-from-the-terminal-and-exiting-afterwards
3.将png图像转换为jpeg
我建议使用作为ImageMagick
convert
一部分的命令行convert image1.xxx image2.yyy