Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gimp: python script not showing in menu

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.

like image 841
kyng Avatar asked Jun 27 '13 05:06

kyng


People also ask

Where do I put Python scripts in gimp?

Where To Put Script-fu Extensions. From the Gimp top menu, go to Edit > Preferences > Folders > Scripts.

What is Python in gimp?

The Python-Fu console is a dialog window running a “Python shell” (a Python interpreter in interactive mode). This console is set up to make use of the internal GIMP library routines of libgimp. You can use the Python-Fu console to interactively test Python commands.


1 Answers

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.

like image 146
jsbueno Avatar answered Sep 24 '22 19:09

jsbueno