kyng kyng - 2 years ago 93
Python Question

Gimp: python script not showing in menu

I followed this tutorial and this is what I have come up so far:

# -*- coding: utf-8 -*-

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)

"Saves the image at a maximum width and height",
"Saves the image at a maximum width and height",
"N N",
"N N",
"<Image>/Image/Resize to max...",


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/ The src is because of eclipse.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download