我有一系列 .xcf 图像,我想保存为 .png 。我可以打开每个文件并保存为 .png ,但由于图像很多,所以需要相当长的时间。
有没有办法一次转换所有图像,或者我必须花费更少的时间来完成这项工作?
提前谢谢。
答案 0 :(得分:5)
我在GIMP中使用Python控制台 - 如果您碰巧在Windows中,请查看如何为GIMP 2.6安装Python扩展(在Linux上,它可以是安装的,也可以是安装的gimp-python包,在Mac OS上可能是一样的)
在GIMP的Python控制台中,你可以访问一个巨大的GIMP API,你可以通过查看help-> Procedure Browser对话框来检查 - 除了拥有Python的所有其他功能,包括文件和strign操作。
你是=在Python-fu控制台中,这是做这样的事情的问题:
import glob
for fname in glob.glob("*.xcf"):
img = pdb.gimp_file_load(fname, fname)
img.flatten()
new_name = fname[:-4] + ".png"
pdb.gimp_file_save(img, img.layers[0], new_name, new_name)
(这将在GIMP默认使用的目录上工作 - 将所需的目录连接到文件路径以便在其他目录上工作)。
如果您需要不止一次,请查看gimp-Python附带的示例插件,并将上面的代码粘贴为GIMP的python插件的核心,供您自己使用。
答案 1 :(得分:3)
答案 2 :(得分:3)
您可以快速创建名为SaveAll的插件。将此代码保存为扩展名为.scm的文件(例如saveall.scm):
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
(define (script-fu-save-all-images)
(let* ((i (car (gimp-image-list)))
(image))
(while (> i 0)
(set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
(gimp-file-save RUN-NONINTERACTIVE
image
(car (gimp-image-get-active-layer image))
(car (gimp-image-get-filename image))
(car (gimp-image-get-filename image)))
(gimp-image-clean-all image)
(set! i (- i 1)))))
(script-fu-register "script-fu-save-all-images"
"<Image>/File/Save ALL"
"Save all opened images"
"Saul Goode"
"Saul Goode"
"11/21/2006"
""
)
将文件放入具有相同扩展名的plugins文件夹中 (在Windows上它是C:\ Program Files \ GIMP 2 \ share \ gimp \ 2.0 \ scripts)。
然后您甚至不必重新启动应用程序。 过滤器菜单 - &gt; Script-Fu - &gt; 更新脚本</ strong>。您将在文件菜单中(位于最底部)拥有全部保存项。它对我来说很容易。
此脚本来自here。
还有another脚本,但我自己没有测试过。
答案 3 :(得分:-1)
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This program is free software; you
; can redistribute it and/or modify
; it under the terms of the GNU
; General Public License as published
; by the Free Software Foundation;
; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the
; hope that it will be useful,
; but WITHOUT ANY WARRANTY;
; without even the implied warranty of
; MERCHANTABILITY or FITNESS
; FOR A PARTICULAR PURPOSE.
; See the GNU General Public License
; for more details.
(define (script-fu-save-all-images inDir inSaveType
inFileName inFileNumber)
(let* (
(i (car (gimp-image-list)))
(ii (car (gimp-image-list)))
(image)
(newFileName "")
(saveString "")
(pathchar (if (equal?
(substring gimp-dir 0 1) "/") "/" "\\"))
)
(set! saveString
(cond
(( equal? inSaveType 0 ) ".jpg" )
(( equal? inSaveType 1 ) ".bmp" )
(( equal? inSaveType 2 ) ".png" )
(( equal? inSaveType 3 ) ".tif" )
)
)
(while (> i 0)
(set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
(set! newFileName (string-append inDir
pathchar inFileName
(substring "00000" (string-length
(number->string (+ inFileNumber i))))
(number->string (+ inFileNumber i)) saveString))
(gimp-file-save RUN-NONINTERACTIVE
image
(car (gimp-image-get-active-layer image))
newFileName
newFileName
)
(gimp-image-clean-all image)
(set! i (- i 1))
)
)
)
(script-fu-register "script-fu-save-all-images"
"<Image>/File/Save ALL As"
"Save all opened images as ..."
"Lauchlin Wilkinson (& Saul Goode)"
"Lauchlin Wilkinson (& Saul Goode)"
"2014/04/21"
""
SF-DIRNAME "Save Directory" ""
SF-OPTION "Save File Type" (list "jpg" "bmp" "png" "tif")
SF-STRING "Save File Base Name" "IMAGE"
SF-ADJUSTMENT "Save File Start Number"
(list 0 0 9000 1 100 0 SF-SPINNER)
)
}
答案 4 :(得分:-2)
此脚本在gimp 2.8
Windows 7中完美运行。
UCHLIN WILKINSON保存GIMP的所有开放图像。
如果您正在扫描大量图像并且只想一次性导出它们,那么很方便。它基于Saul Goode的脚本,扩展为提示图像基本名称,目录等。
将其保存为Gimp脚本目录中的saveall.scm。例如。 〜/ .gimp-2.8 /脚本/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This program is free software; you
; can redistribute it and/or modify
; it under the terms of the GNU
; General Public License as published
; by the Free Software Foundation;
; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the
; hope that it will be useful,
; but WITHOUT ANY WARRANTY;
; without even the implied warranty of
; MERCHANTABILITY or FITNESS
; FOR A PARTICULAR PURPOSE.
; See the GNU General Public License
; for more details.
(define (script-fu-save-all-images inDir inSaveType
inFileName inFileNumber)
(let* (
(i (car (gimp-image-list)))
(ii (car (gimp-image-list)))
(image)
(newFileName "")
(saveString "")
(pathchar (if (equal?
(substring gimp-dir 0 1) "/") "/" "\\"))
)
(set! saveString
(cond
(( equal? inSaveType 0 ) ".jpg" )
(( equal? inSaveType 1 ) ".bmp" )
(( equal? inSaveType 2 ) ".png" )
(( equal? inSaveType 3 ) ".tif" )
)
)
(while (> i 0)
(set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
(set! newFileName (string-append inDir
pathchar inFileName
(substring "00000" (string-length
(number->string (+ inFileNumber i))))
(number->string (+ inFileNumber i)) saveString))
(gimp-file-save RUN-NONINTERACTIVE
image
(car (gimp-image-get-active-layer image))
newFileName
newFileName
)
(gimp-image-clean-all image)
(set! i (- i 1))
)
)
)
(script-fu-register "script-fu-save-all-images"
"<Image>/File/Save ALL As"
"Save all opened images as ..."
"Lauchlin Wilkinson (& Saul Goode)"
"Lauchlin Wilkinson (& Saul Goode)"
"2014/04/21"
""
SF-DIRNAME "Save Directory" ""
SF-OPTION "Save File Type" (list "jpg" "bmp" "png" "tif")
SF-STRING "Save File Base Name" "IMAGE"
SF-ADJUSTMENT "Save File Start Number"
(list 0 0 9000 1 100 0 SF-SPINNER)
)