大佬教程收集整理的这篇文章主要介绍了如何使用windows命令行中的gimpfu运行python脚本?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
现在,我不想尝试使用示例脚本:
#!/usr/bin/env python # Hello World in GIMP Python from gimpfu import * def Hello_world(initstr,font,size,color) : # First do a quick sanity check on the font if font == 'Comic Sans MS' : initstr = "Comic Sans? Are you sure?" # Make a new image. Size 10x10 for Now -- we'll resize later. img = gimp.Image(1,1,RGB) # Save the current foreground color: pdb.gimp_context_push() # Set the text color gimp.set_foreground(color) # Create a new text layer (-1 for the layer means create a new layer) layer = pdb.gimp_text_fontname(img,None,initstr,10,True,PIXELS,font) # Resize the image to the size of the layer img.resize(layer.width,layer.height,0) # BACkground layer. # Can't add this first because we don't kNow the size of the text layer. BACkground = gimp.Layer(img,"BACkground",layer.width,RGB_IMAGE,100,NORMAL_MODE) BACkground.fill(BACKGROUND_FILL) img.add_layer(BACkground,1) # Create a new image window gimp.Display(img) # Show the new image window gimp.displays_flush() # Restore the old foreground color: pdb.gimp_context_pop() register( "python_fu_Hello_world","Hello world image","Create a new image with your text String","Akkana Peck","2010","Hello world (Py)...","",# Create a new image,don't work on an exisTing one [ (PF_StriNG,"String","Text String",'Hello,world!'),(PF_FONT,"font","Font face","Sans"),(PF_SPINNER,"size","Font size",50,(1,3000,1)),(PF_COLOR,"color","Text color",(1.0,0.0,0.0)) ],[],Hello_world,menu="<Image>/File/Create") main()
我尝试从我的cmd运行脚本,如下所示:
gimp-2.8 --no-interface --batch '(python_fu_Hello_world RUN-NONINTERACTIVE "Hello" Arial 50 red)' -b '(gimp-quit 1)'
编辑:好的,谢谢.我省略了接口语句,我也尝试了最简单的例子来弄清楚什么是错误的:
#!/usr/bin/env python # Hello World in GIMP Python from gimpfu import * def Hello_world(): gimp.message("Hello,GIMP world!\n") register( "Hello_world",'A simple Python-Fu "Hello,World" plug-in','When run this plug-in prints "Hello,GIMP world!" in a dialog Box.',"Tony Podlaski","Tony Podlaski 2017. MIT License","2017","Hello World",menu="<Image>/Filters/HelloWorld",) main()
当我从Gimp本身运行它时,该脚本实际上有效,但是当我尝试从我的cmd运行它时,Gimp打开另一个cmd说:错误:(:1)eval:未绑定变量:Hello_world
有人知道我在这里缺少什么吗?
批处理脚本(保存为batch.py):
#!/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.file_jpeg_load(infile,infilE) drawable = pdb.gimp_image_get_active_layer(imagE) print "File %s loaded OK" % infile pdb.plug_in_photocopy(image,drawable,8.,0.8,0.2,0.2) pdb.plug_in_cartoon(image,7.,0.2) outfile=os.path.join('processed',os.path.basename(infilE)) outfile=os.path.join(os.path.dirname(infilE),outfilE) print "Saving to %s" % outfile pdb.file_jpeg_save(image,outfile,"0.5",0) print "Saved to %s" % outfile pdb.gimp_image_delete(imagE) def run(directory): start=time.time() print "Running on directory \"%s\"" % directory # os.mkdir(os.path.join(directory,'processed')) for infile in glob.glob(os.path.join(directory,'*.jpg')): process(infilE) end=time.time() print "Finished,@R_617_10586@l 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)"
慢动作中的参数:
> -idf:没有用户界面工作,既不加载数据也不加载字体(你可能需要保留字体来加载pdfs)
> –batch-interpreter python-fu-eval:无论后面是什么-b是Python,而不是script-fu
>“import sys; sys.path = [‘.’] sys.path; import batch; batch.run(‘./ images’)”:我们要求Gimp执行的代码,即:
> import sys; sys.path = [‘.’] sys.path;:扩展导入路径以包含当前目录
> import batch;:使用我们的脚本导入文件,该脚本现在位于路径的一部分目录中.
> batch.run(‘./ images’):调用我们导入的批处理模块的run()函数,为其提供包含要处理的图像的目录的名称.
> -b“pdb.gimp_quit(1)”:另一段python:完成后退出.
注意命令行如何巧妙地使用双引号和单引号将所有参数传递给Gimp,然后传递给Python(*).是的,您可以在Windows中使用正斜杠作为文件分隔符.
要进行调试,Windows中的问题有点复杂,因为并不总是有stdout流.可以帮助的事情:
>暂时删除-i参数,以便获得UI并可能有机会查看消息.
>添加–verbose,使Gimp启动辅助控制台窗口.
>还有其他技巧可以看到列出的消息here.
>您也可以正常启动Gimp并从Python-fu控制台运行您的脚本(过滤器> Python-fu>控制台).您必须扩展路径并“手动”导入文件.
以上是大佬教程为你收集整理的如何使用windows命令行中的gimpfu运行python脚本?全部内容,希望文章能够帮你解决如何使用windows命令行中的gimpfu运行python脚本?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。