EDITED HEAVILY有一些新信息(和赏金)
我正在尝试在python中为gimp创建一个插件.(在Windows上)这个页面http://gimpbook.com/scripting/notes.html建议从shell运行它,或者查看〜/ .xsession-errors
既不工作.我可以从cmd shell运行它,如
gimp-2.8.exe -c --verbose ##(由http://gimpchat.com/viewtopic.php?f=9&t=751建议)
这会导致"pdb.gimp_message(...)"的输出转到终端.
但是!!! 这只有当一切都按预期运行时才有效,我在崩溃时没有输出.
我试过打印声明,它们无处可去.
这个人有类似的问题,但讨论却陷入了困境. 插件通常不起作用,我该如何调试?
在某些地方,我看到了在python-fu控制台中运行它的建议.
这让我无处可去.我需要注释掉导入gimpfu,因为它会引发错误,而且我没有让gtk工作.
我当前的问题是,即使插件在菜单上注册并显示,当出现一些错误并且它没有按预期运行时,我也不知道从哪里开始寻找提示.(我试过点击各种情况,w - w/o选择,没有图像.)
我能够从http://gimpbook.com/scripting/复制并执行示例插件 ,我得到了,工作,但是当我做出改变时,我不知道是什么,并且逐行变形现有程序是乏味的.(每次都要关闭和恢复gimp)
总结一下 -
1-我可以刷新插件而无需重启gimp吗?(所以至少我的慢变形会更快)
2-我可以从python-fu shell运行插件.(而不是只是导入它们以确保它们解析.)
3-是否有错误日志我错过了,或者有什么效果?
4-有没有办法在shell上运行gimp来查看输出?(我最好在cygwin(或virtualbox ..)下)?
5-我还没有查找如何将winpdb连接到现有进程.我如何将它连接到在gimp中运行的python进程?
谢谢
我想要做的是从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) 我需要为GIMP开发一个插件,并希望继续使用PyCharm进行Python编辑等.
仅供参考,我在Windows上.
在指示PyCharm使用GIMP附带的Python解释器之后:
我还添加了一个路径来gimpfu.py
摆脱错误from gimpfu import *
:
这可以修复导入时的错误,即使设置为Excluded
.
我尝试用这个目录设置Sources
,Resources
并Excluded
仍然得到了常量,如错误RGBA-IMAGE
,TRANSPARENT_FILL
,NORMAL_MODE
,等.
关于如何扭曲PyCharm为GIMP插件开发做好事的任何想法?
没有真正运行PyCharm的任何代码,它实际上只是用作一个很好的代码编辑器,便于修改控件等.
我遵循了本教程,这是我到目前为止所得到的:
#!/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) 我刚刚开始学习使用Python编写Gimp脚本,并且想知道如何将文本输出到控制台?我在Windows 7上使用的是2.7.5版.
我尝试了print函数,但它没有向python-fu控制台或使用Gimp启动的开发控制台写任何东西.有没有我应该用来做这个功能?或者这是2.7.5版本的问题?我发现了一些"gimp-message",但这似乎与Scheme一起使用的函数(Script-fu)
谢谢!
(也在这里发布了一个帖子)
我是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) 我想调整目录中每个 jpg 的大小。
这是我找到的 gimp 脚本。对我来说看起来很明智。
(define (batch-resize pattern)
(let*
((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-active-drawable image)))
(cur-width (car (gimp-image-width image)))
(cur-height (car (gimp-image-height image)))
(width (* 0.25 cur-width))
(height (* 0.25 cur-height))
)
(gimp-message filename)
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(let
((nfilename (string-append "thumb_" filename)))
(gimp-file-save RUN-NONINTERACTIVE image drawable nfilename nfilename)
)
(gimp-image-delete image)
)
(set! filelist (cdr filelist))
)
)
) …
Run Code Online (Sandbox Code Playgroud) 在网络上,我可以找到有关使用 python 编写 gimp 脚本的各种示例。
http://www.jamesh.id.au/software/pygimp/ http://www.gimp.org/docs/python/pygimp.html
我们需要导入gimpfu
模块才能使示例工作。我们在哪里可以获得 Windows 上的 PyGIMP 安装程序?似乎该项目已死并且链接已损坏。
我想编写一个 Gimp-Python 插件,以便从当前图像中导出所有 SVG 路径。这看起来很简单,但我坚持使用 pdb 调用,我可能没有正确调用过程,所以我需要你的帮助。
这是我的代码:
#!/usr/bin/env python
from gimpfu import *
def exportToSvg(img, layer) :
gimp.pdb.vectors_export_to_file(img,"C:/Users/Public/Documents/output.svg",0)
register(
"ExportToSvg",
"Export all SVG paths",
"Export all SVG paths from current image",
"My Name",
"My company",
"2015",
"<Image>/MyScripts/Export to svg",
"*",
[],
[],
exportToSvg)
main()
Run Code Online (Sandbox Code Playgroud)
打开 Gimp 并加载图像后,当我单击我的插件时,我收到此错误:
调用 « gimp-procedural-db-proc-info » 时出错:未找到过程«vectors-export-to-file »
当我在 Gimp PDB 中搜索时,我可以找到“gimp-vectors-export-to-file”,那么问题是什么?我应该如何调用这个程序?
我正在为 GIMP 开发一个 python 插件,我想获取图层的 RGB 矩阵作为 numpy 数组。要访问 python 插件中的层,我使用下一个代码:
def python_function(img, layer):
layer = img.layers[0]
Run Code Online (Sandbox Code Playgroud)
我想创建一个layer
变量,而不是一个 gimp.Image 变量,一个包含每个像素的 RGB 值的 numpy 数组。我在其他nonGimp-Python代码用的是这个下一行:frame2 = misc.imread('C:\Users\User\Desktop\image2.png').astype(np.float32)
。如果我打印,frame2
我会得到一个这样的矩阵,其中包含每个像素的 RGB 值:
[[[ 111. 179. 245.]
[ 111. 179. 245.]
[ 111. 179. 245.]
...,
[ 95. 162. 233.]
[ 95. 162. 233.]
[ 95. 162. 233.]]
[[ 111. 179. 245.]
[ 111. 179. 245.]
[ 111. 179. 245.]
...,
[ 95. 162. 233.]
[ 95. 162. 233.] …
Run Code Online (Sandbox Code Playgroud)