问题
I followed this tutorial and this is what I have come up so far:
#!/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()
But the plugin woun't show up in gimp menu (I'm using gimp 2.8). Gave the file chmod a+x rights. Might the file location be a problem: /.gimp-2.8/plug-ins/src/resize.py? The src is because of eclipse.
回答1:
If your script has any syntax errors, it won't show up in the menu at all - the above code does have a syntax error on the very first line of code from gimpfu import*
(missing a space before the *
)
One easy way to check for syntax errors is to try to run the script as a stand alone (it will fail when it can't find the "gimpfu" module outside GIMP, but by that time, the syntax is parsed - another way is to use a lint utility like pyflakes to check the syntax.
Other run-time errors that your script might contain should appear in a pop-up window when running it from GIMP - at that stage, you can only update your script and retry it from the menus. If you change the input or output parameters from your script, though, you have to restart GIMP .
And yes, the "file location" is a problem - you must put your code in a directory specified for Plug-ins in GIMP's preferences - by default these are ~/.gimp-2.8/plug-ins/
or /usr/lib[64]/gimp/2.0/plug-ins
- with no "src" - if your IDE does not let you specify where to put your files, you have to copy them there yourself, or add the src
dirs in GIMP preferences.
来源:https://stackoverflow.com/questions/17334993/gimp-python-script-not-showing-in-menu