一次性将多个文件保存为 (GIMP)

5

我有一系列的.xcf图片,我想保存为.png格式。我可以打开每个文件并另存为.png,但由于图片数量很多,这需要花费相当长的时间。

有没有一种方法可以一次转换所有图片,或者有其他方法可以让我在这项工作上花费更少的时间呢?

提前感谢您的帮助。

6个回答

3
我会使用GIMP内置的Python控制台来完成这个任务 - 如果你正在使用Windows系统,请查看如何安装GIMP 2.6的Python扩展(在Linux上,它可能已经被安装或者只需要安装gimp-python包,Mac OS上也可能是同样的方法)。
在GIMP的Python控制台中,您可以通过查看帮助->过程浏览器对话框来访问大量的GIMP API - 除了具有Python的所有其他功能,包括文件和字符串操作。
一旦您进入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插件的核心。


作为批量转换工具并不是GIMP的核心目标。虽然可以通过第三方脚本来完成,但是对于脚本生态系统的支持还有待提高。 - jsbueno

3

如果您已安装 imagemagick,则可以这样做:

mogrify -format png *.xcf

这将自动将它们转换到同一目录中。还可以阅读 man mogrify 或者这个链接 查看其他选项。


2

您可以快速创建一个名为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" 
 "" 
 ) 

将文件与相同扩展名放入插件文件夹中(在Windows上是C:\Program Files\GIMP 2\share\gimp\2.0\scripts)。然后您甚至不需要重新启动应用程序。选择“滤镜”菜单->“Script-Fu” ->“更新脚本”。您将在“文件”菜单中(在底部)看到“保存全部”选项。这对我来说非常快速和容易。此脚本来自此处。还有另一个脚本,但我自己没有测试过。

-2
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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)
 )

}

-2
是的,有一种方法,而且不需要编程技能。只需安装免费的批量图像处理插件[链接1] [存档]。该项目是开源的,可以在GitHub上找到[链接3]。

-3

这个脚本在 Windows 7 的 gimp 2.8 上完美运行。

UCHLIN WILKINSON 从 GIMP 中保存所有打开的图像。

如果您正在扫描大量图像并且只想一次性导出它们,那么这将非常方便。它基于 Saul Goode 的脚本,并扩展了提示图像基本名称、目录等功能。

将其保存为 saveall.scm 并放置在 Gimp 脚本目录中。例如:~/.gimp-2.8/scripts/

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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)
 )

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接