Windows 使用Gimp在命令行上按x和y的百分比调整图像大小

Windows 使用Gimp在命令行上按x和y的百分比调整图像大小,windows,command-line-interface,image-resizing,gimp,Windows,Command Line Interface,Image Resizing,Gimp,好吧,这应该是可能的。我知道ImageMagick的convert使这个任务变得微不足道,但我不能使用ImageMagick,因此我倾向于Gimp(在Windows上) 我尝试过这个诡计的脚本: (define (resize-image filename new-filename scale) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car

好吧,这应该是可能的。我知道ImageMagick的
convert
使这个任务变得微不足道,但我不能使用ImageMagick,因此我倾向于Gimp(在Windows上)

我尝试过这个诡计的脚本:

(define (resize-image filename new-filename scale)
  (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
         (drawable (car (gimp-image-get-active-layer image)))
         (width (gimp-image-width image))
         (height (gimp-image-height image)))
    (gimp-image-scale-full image (* width scale) (* height scale) INTERPOLATION-CUBIC)
    (gimp-file-save RUN-NONINTERACTIVE image drawable new-filename new-filename)
    (gimp-image-delete image)))
与我一起跑步的人:

gimp-2.8 -i -b "(resize-image \"image.jpg\" \"image-small.jpg\" 0.5)" -b "(gimp-quit 0)"
但我得到了这个错误:

(gimp-2.8:22244): LibGimpBase-WARNING **: gimp-2.8: gimp_wire_read(): error

(gimp-2.8:22244): LibGimpBase-WARNING **: gimp-2.8: gimp_wire_read(): error
batch command experienced an execution error:
Error: ( : 1) *: argument 1 must be: number
我的解决方案受到以下帖子的启发:


缩小图像的最短代码:

image=pdb.gimp_file_load('/tmp/bigger.png','/tmp/bigger.png')
image.scale(int(image.width*.5),int(image.height*.5))
pdb.gimp_file_save(image, image.active_layer, '/tmp/smaller.png','/tmp/smaller.png')
所以,你仍然可以把所有的东西放在一行中。在Linux中,这会让您(振作起来):

IIRC,由于Windows shell如何使用引号,您必须使用双引号来分隔shell参数,因此如果在Python字符串周围使用单引号(未经测试),事情会更容易:

但是,在启动Gimp时(尤其是在WIndows上)会有很大的开销,因此如果需要处理多个文件,最好编写代码在目录中的文件上循环。这会变得更大一些,可能需要将代码保留在模块中。从我以前作为windows用户的档案中:

假设您有这样一个batch.py文件(显然您必须改进process()函数,特别是向其传递参数:

#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os,glob,sys,time
from gimpfu import *

def process(infile):
    print "Processing file %s " % infile
    image=pdb.gimp_file_load('/tmp/bigger.png','/tmp/bigger.png');
    image.scale(int(image.width*.5),int(image.height*.5));
    pdb.gimp_file_save(image, image.active_layer, '/tmp/smaller.png','/tmp/smaller.png')
    pdb.gimp_image_delete(image)

def run(directory):
    start=time.time()
    print "Running on directory \"%s\"" % directory
    for infile in glob.glob(os.path.join(directory, '*.jpg')):
            process(infile)
    end=time.time()
    print "Finished, total processing time: %.2f seconds" % (end-start)

if __name__ == "__main__":
        print "Running as __main__ with args: %s" % sys.argv
您可以(在Windows中)将其称为:


问题是,您将通过命令行参数导入一个小型scheme/python程序,而不会过度解释引号或双引号。那么,Linux、OSX或Windows?操作系统是Windows。无论如何,我可以向Gimp传递一个脚本以避免引用问题吗?从技术上讲,您不会调用Gimp脚本,而是调用一个小型专业程序在Gimp环境中运行的gram。该程序可以是自包含的,也可以调用现有的Gimp脚本,或者,对于Python,导入一个模块并调用其中的函数。感谢您的贡献,但我无法使Python在我的Windows机器上正常工作,因此我求助于一种也不起作用的诡计解决方案(请查看我的更新答案)。我无法帮助您使用脚本fu。最好告诉我Python出现了什么问题。您使用的是什么版本的Gimp?2.8还是停留在2.6上?最终,我使用了Python库而不是Gimp。无论如何,感谢您的帮助。这是您应该开始使用的:)我无法在GIMP 2.10上实现这一点,它引入了一个新的GIMP-console-2.10.exe,它没有将--batch解释器列为有效选项。有什么建议吗?
gimp -idf --batch-interpreter python-fu-eval -b "image=pdb.gimp_file_load('/tmp/bigger.png','/tmp/bigger.png');image.scale(int(image.width*.5),int(image.height*.5));pdb.gimp_file_save(image, image.active_layer, '/tmp/smaller.png','/tmp/smaller.png')" -b "pdb.gimp_quit(1)"
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os,glob,sys,time
from gimpfu import *

def process(infile):
    print "Processing file %s " % infile
    image=pdb.gimp_file_load('/tmp/bigger.png','/tmp/bigger.png');
    image.scale(int(image.width*.5),int(image.height*.5));
    pdb.gimp_file_save(image, image.active_layer, '/tmp/smaller.png','/tmp/smaller.png')
    pdb.gimp_image_delete(image)

def run(directory):
    start=time.time()
    print "Running on directory \"%s\"" % directory
    for infile in glob.glob(os.path.join(directory, '*.jpg')):
            process(infile)
    end=time.time()
    print "Finished, total processing time: %.2f seconds" % (end-start)

if __name__ == "__main__":
        print "Running as __main__ with args: %s" % sys.argv
gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)"