我想要做的是从python程序打开gimp(也许使用subprocess.Popen),同时,gimp将以一个python脚本开始,该脚本将打开一个图像并添加一个图层......好吧,如何我可以实现这一点(我希望GIMP有更好的文档......)?
更新:
我这样做了:subprocess.Popen(["gimp", "--batch-interpreter" , "python-fu-eval" , "-b" ,"\'import sys; sys.path.append(\"/home/antoni4040\"); import gimpp; from gimpfu import *; gimpp.main()\'"])
但是,即使控制台说"批处理命令成功执行",也没有任何反应......
UPDATE2:
from gimpfu import *
def gimpp():
g = gimp.pdb
images = gimp.image_list()
my_image = images[0]
layers = my_image.layers
new_image = g.gimp_file_load_layer("/home/antoni4040/???????/Layout.png")
my_image.add_layer(new_image)
new_layer = g.gimp_layers_new(my_image, 1024, 1024, RGBA_IMAGE, "PaintHere", 0, NORMAL_MODE)
my_image.add_layer(new_layer)
register('GimpSync', "Sync Gimp with Blender", "", "", "", "", "<Image>/SyncWithBlender", '*', [], [], gimpp)
main()
Run Code Online (Sandbox Code Playgroud) 我遵循了本教程,这是我到目前为止所得到的:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#http://www.ibm.com/developerworks/library/os-autogimp/
from gimpfu import*
def plugin_main(timg, tdrawable, maxh=540, maxw=800):
currentWidth = tdrawable.width
currentHeight = tdrawable.height
newWidth = currentWidth
newHeight = currentHeight
if (maxw < newWidth):
newWidth = maxw
newHeight = (float(currentHeight) / (float(currentWidth) / newWidth))
if (maxh < newHeight):
newHeight = maxh
newWidth = (float(currentWidth) / (float(currentHeight) / newHeight))
pdb.gimp_image_scale(timg, newWidth, newHeight)
register(
"python_fu_resize",
"Saves the image at a maximum width and height",
"Saves the image at a maximum width and …
Run Code Online (Sandbox Code Playgroud) 随着GIMP福,我能救的内容一个层(至少,这就是我interprete的定义,gimp_file_save
因为它需要的参数drawable
).
现在,我有以下脚本:
from gimpfu import *
def write_text():
width = 400
height = 100
img = gimp.Image(width, height, RGB)
img.disable_undo()
gimp.set_foreground( (255, 100, 20) )
gimp.set_background( ( 0, 15, 40) )
background_layer = gimp.Layer(
img,
'Background',
width,
height,
RGB_IMAGE,
100,
NORMAL_MODE)
img.add_layer(background_layer, 0)
background_layer.fill(BACKGROUND_FILL)
text_layer = pdb.gimp_text_fontname(
img,
None,
60,
40,
'Here is some text',
0,
True,
30,
PIXELS,
'Courier New'
)
drawable = pdb.gimp_image_active_drawable(img)
# Either export text layer ...
# pdb.gimp_file_save(img, drawable, …
Run Code Online (Sandbox Code Playgroud) 我是gimp python-fu编程的新手我已经花了4天没有运气来弄清楚哪个是最合适的函数来获取绘制路径的坐标并在gtk消息框上显示输出,如下图所示.
请考虑我在Windows机器上开发
我尝试过这样的代码:
import gtk, gimpui
from gimpfu import *
def debugMessage(Message):
dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, Message)
dialog.run()
dialog.hide()
def python_fu_mahdicoordinates(image, layer):
vectors = pdb.gimp_image_get_active_vectors(image)
nstrokes, strokes = pdb.gimp_vectors_get_strokes(vectors)
stroke_type, n_points, cpoints, closed = pdb.gimp_vectors_stroke_get_points(vectors, strokes[0])
x0 = cpoints[0]
y0 = cpoints[1]
x1 = cpoints[6]
y1 = cpoints[7]
x2 = cpoints[12]
y2 = cpoints[13]
x3 = cpoints[18]
y3 = cpoints[19]
debugMessage('(' + str(x0) + ', ' + str(y0) + ', '+str(x1) + ', '+str(y1) + ', '+str(x2) …
Run Code Online (Sandbox Code Playgroud) 在 Windows 环境中,我想调用 GIMP 来执行 python-fu 脚本(通过 BAT 文件),但是我使用的命令行调用没有产生预期的结果。
例如,考虑以下名为 的 python-fu 脚本makeafile_and_quit.py
,它位于我的 GIMPplug-ins
文件夹中。其目的是加载现有图像并以不同名称保存:
#!/usr/bin/env python
# Sample call from GIMP's python-fu console:
# pdb.python_fu_makeafile_and_quit_script()
from gimpfu import *
def makeafile_and_quit( ) :
FILEPATH = 'C:\\path\\to\\file.JPG'
IMAGE = pdb.gimp_file_load( FILEPATH, FILEPATH )
pdb.gimp_file_save( IMAGE, pdb.gimp_image_get_active_drawable( IMAGE ), FILEPATH + '_2.jpg', FILEPATH + '_2.jpg' )
pdb.gimp_quit(0)
return
# PLUGIN REGISTRATION
# This is the plugin registration function
register(
'makeafile_and_quit_script',
'v0.0',
'A new concept',
'Author',
'Author',
'Just now', …
Run Code Online (Sandbox Code Playgroud) 我有一个带有嵌套层结构的XCD文件:
image
front-layer
content-layer
content-layer-name-1
content-layer-name-2
content-layer-name-3
back-layer
Run Code Online (Sandbox Code Playgroud)
我打开该文件image = pdb.gimp_file_load(xcf_file, xcf_file)
,并可以得到front-layer
,content-layer
并且back-layer
为image.layers[0]
,image.layers[1]
和image.layers[2]
.但Gimp无法content-layer
通过列表索引获取子层.
我可以使用pdb.gimp_image_get_layer_by_name(image, 'content-layer-name-3')
,但我不知道图层的名称.
我尝试pdb.gimp_item_get_children(image.layers[1])
,但这个方法返回INT32ARRAY
项目的孩子列表,我还没有找到如何通过其ID检索项目.
如何在Gimp(2.8)中使用Python从组层获取子层?
我在通过 GIMP 在 python 中保存图像时遇到问题。我可以获得图像并应用我想要的效果,但是当我去保存时,它只保存一层而不是所有内容(注意:背景是透明的)并且因为背景是透明的,所以我无法保存任何东西透明背景。我正在使用的代码发布在下面:
image_array = gimp.image_list()
i=0
for image in image_array:
img = image_array[i]
layers = img.layers
last_layer = len(layers)-1
try:
disable=pdb.gimp_image_undo_disable(img)
pdb.gimp_layer_add_alpha(layers[0])
drw = pdb.gimp_image_active_drawable(img)
pdb.plug_in_colortoalpha(img,drw,(0,0,0))
drw = pdb.gimp_image_active_drawable(img)
enable = pdb.gimp_image_undo_enable(img)
except:
print "ERROR"
pdb.file_png_save(img, drw, "C:\\Users\\jammer\\Desktop\\test.png",
"test.png",0,9,1,1,1,1,1)
i+=1
Run Code Online (Sandbox Code Playgroud)
我也尝试过file_png_save2
,但我感觉问题出在 drw 对象中,因为我只想复制单击文件->导出并另存为 PNG的选项,而无需通过 GUI 执行此操作。我宁愿让它自动保存(我有 49 个图像,每个图像都会自动命名,但首先我需要让它用一张图像正确导出)。正如我之前所说,上面的代码只导出透明背景,即使更改为 GIF 也不能解决问题。如何在保留所有图层和透明背景的同时将文件导出为 PNG?
我似乎找不到任何方法在python-fu接口的任何地方将组图层添加到另一个组图层.
我试图在Gimp.Layer对象上找到方法,但没有运气.
如何使用python-fu将组图层添加到另一个图层组?
我是 python-fu 的新手(第二天),所以我的问题可能看起来很天真:我想从“r400r.png”中选择一个矩形部分,将其旋转 90 度,然后将我的选择保存在“ r400ra.png”。
到目前为止,我尝试了以下几行:
for fv in range(400,401):
fn='r%sr.png' % fv
img=pdb.gimp_file_load('/path/'+fn,fn)
drw=pdb.gimp_image_get_active_layer(img)
img1=pdb.gimp_image_new(1024,1568,0)
lyr=pdb.gimp_layer_new(img1,1024,1568,0,'ly1',0,0)
pdb.gimp_rect_select(img,10,200,1422,1024,2,0,0)
drw=pdb.gimp_rotate(drw,0,1.570796327)
pdb.script_fu_selection_to_image(img1,drw)
f0=fn[:5]+'a'+fn[5:]
pdb.gimp_file_save(drw,'/path/'+f0,f0)
Run Code Online (Sandbox Code Playgroud)
“lyr”层之所以存在,是因为我的理解是它是必须的,尽管我不清楚为什么。“for”循环最终应该批量处理一堆文件;为了测试,它仅限于一个文件。我在尝试执行“script_fu_selection_to_image”时收到错误。
您能给我指出正确的方向吗?
谢谢,SxN
我试图找出一种简单的方法来执行我编写的 Python-Fu 脚本,该脚本在 Gimp 的 Python-Fu 解释器插件的单线程模式下工作,但由于Windows 非 POSIX/OS.Fork 限制在Pool.map_async()
. 作为一种解决方法,我试图直接从 cmd shell 调用脚本,但无法找出正确的命令来完成它。我的 PATH 变量中有 gimp bin 目录,我正在尝试实现如下所示的内容...
c:\>gimp-console-2.8 --no-interface --batch "(python-fu execfile('myPyFuScript.py'))"
c:\>gimp-console-2.8 --no-interface --batch "myPyFuScript.py"
Run Code Online (Sandbox Code Playgroud)
有没有办法让 Gimp 使用它的 Python-Fu 模块从 Windows cmd shell 发出的命令中执行 python 脚本?
只是为了增加背景,我从以下文档中汲取灵感......
来自 Shell 的 GIMP Python 调用
所有这一切意味着您可以使用 (plug-in-script-fu-eval ...) 评估器直接从您的 shell 轻松调用 GIMP Python 插件,例如上面的插件:
gimp --no-interface --batch '(python-fu-console-echo RUN-NONINTERACTIVE "another string" 777 3.1416 (list 1 0 0))' '(gimp-quit 1)'
Run Code Online (Sandbox Code Playgroud) 我有一个包含20多个图层的.xcf文件,用于制作精灵文件.
我想将所有这些图层保存为单独的文件,只包含每个图层的内容和大小.
我为gimp找到了这个脚本:https://github.com/jiilee/gimp
不幸的是,该脚本会创建具有图像完整大小的文件,而不是每个图层的大小.
举个例子:一张700px宽,400px高的图像.一层放置在x:100px,y:29px,宽度:72px,高度:21px; 我找到的脚本生成一个700px x 400px的文件,而不是因为我需要72px x 21px.
是否可以自动执行此操作?
我正在尝试使用 pythonfu 编写一个 gimp 脚本。但是,当我尝试在本地运行脚本时,出现错误
`--> ./vvv.py
Traceback (most recent call last):
File "./vvv.py", line 5, in <module>
from gimpfu import *
ImportError: No module named gimpfu
Run Code Online (Sandbox Code Playgroud)
我认为该脚本可能只能通过 gimp 加载。但是,脚本不会出现在 gimp 菜单中。在这种情况下,我如何获得错误输出?
我一直在尝试从script-fu切换到python-fu,我无法弄清楚我应该为"image"参数传递什么.在script-fu中它只是一个整数,但是当我将相同的整数放入python-fu时,它只是说它是错误的类型.与字符串和花车相同......我应该放在这里什么?文档只是说它所采用的参数是"IMAGE",但这是什么意思?我在哪里找到它?我怎么得到它?
pdb.gimp_image_get_layers(image)
Run Code Online (Sandbox Code Playgroud)
gimp ×13
python-fu ×13
python ×8
gimpfu ×5
xcf ×2
batch-file ×1
command-line ×1
layer ×1
parameters ×1
save-image ×1
script-fu ×1
scripting ×1
shell ×1
subprocess ×1