微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我已经尝试过这个Guile脚本:

(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)"

但我得到这个错误

PHPUnit命令行工具不起作用

linux命令“符号

Windows API彩色输出到Powershell / cmd.exe中的标准输出

Windows cygwin相当于Mac OS X打开命令

强制CLI使用现有的进程?

(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

我的解决scheme受到这个职位的启发:

http://warunapw.blogspot.it/2010/01/batch-resize-images-in-gimp.html

将stderr和stdoutredirect到同一个文件的顺序

如何在Windows命令提示符下创build并执行一个完整的命令文件

Linux – 在CLI中更改主机名

将Windows对话框错误消息redirect到控制台

在没有GUI的情况下在Linux上签名的BlackBerry代码

缩小图像的最短代码

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中,这给(自己):

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,"/tmp/smaller.png","/tmp/smaller.png")' -b 'pdb.gimp_quit(1)'

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

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),'/tmp/smaller.png')" -b "pdb.gimp_quit(1)"

但是,启动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,'/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中):

gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐