11

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.

morten.c
  • 3,414
  • 5
  • 40
  • 45
kyng
  • 457
  • 1
  • 6
  • 13

1 Answers1

13

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.

Dan Loughney
  • 4,647
  • 3
  • 25
  • 40
jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Made some changes: added the missing space and moved the script to `/usr/lib/gimp/2.0/plug-ins`. Now it appears in menu. Thanks. – kyng Jun 29 '13 at 16:36
  • 4
    Another tip for debuging: start gimp from command line and you can see what kind of error messages appear. – kyng Jul 01 '13 at 11:04
  • 8
    Ensure that the script is executable. Running `$ chmod +x plugin.py` fixed the issue for me. – arunkumar Aug 10 '16 at 22:58
  • 1
    jsbueno says it above, but to reinforce: Gimp considers python scripts to be plug-ins and not scripts. If you are configuring a custom folder for python, do it in the Plug-ins preferences. – Dan Loughney Dec 09 '16 at 12:33
  • I had this same issue, I checked the script in the console (no errors), but was able to diagnose the cause by opening GIMP in verbose mode (create a shortcut to GIMP and add `--verbose` to the path) - GIMP threw a "Removing duplicate PDB procedure" error when it tried to load the missing script. This led me to the source of the issue: I'd copied the code from another plugin as a template, and had failed to change the name in the Register section - i.e. the first property: `register( "plugin_name"` - as soon as I changed that to something *unique*, it showed up in the menu – LoquaciousDandy Aug 01 '18 at 13:36