kyn*_*yng 9 python gimp python-fu gimpfu
我遵循了本教程,这是我到目前为止所得到的:
#!/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 height",
"N N",
"N N",
"2013",
"<Image>/Image/Resize to max...",
"*",
[],
[],
plugin_main)
main()
Run Code Online (Sandbox Code Playgroud)
但插件不会出现在gimp菜单中(我正在使用gimp 2.8).给文件chmod一个+ x权限.可能文件位置有问题:/.gimp-2.8/plug-ins/src/resize.py?src是因为eclipse.
jsb*_*eno 10
如果您的脚本有任何语法错误,它根本不会显示在菜单中 - 上面的代码在第一行代码上确实存在语法错误 from gimpfu import*
(缺少前面的空格*)
检查语法错误的一种简单方法是尝试将脚本作为独立运行(当它无法在GIMP外部找到"gimpfu"模块时会失败,但到那时,语法被解析 - 另一种方式是使用像pyflakes这样的lint实用程序来检查语法.
当您从GIMP运行脚本时,脚本可能包含的其他运行时错误应显示在弹出窗口中 - 在该阶段,您只能更新脚本并从菜单重试.但是,如果从脚本更改输入或输出参数,则必须重新启动GIMP.
是的,"文件位置" 是一个问题 - 您必须将您的代码放在GIMP首选项中为插件指定的目录中 - 默认情况下这些是- ~/.gimp-2.8/plug-ins/或者/usr/lib[64]/gimp/2.0/plug-ins没有"src" - 如果您的IDE不允许您指定位置要放置文件,您必须自己复制它们,或者src在GIMP首选项中添加目录.