Post Reply 

Attempting to Write Python Plugin and Failing Miserably

May 22, 2012, 00:42
Post: #1
Sad Attempting to Write Python Plugin and Failing Miserably
Hello Gimp Forums members,

I am attempting to write (what I thought would be) a simple plugin for GIMP that does three things:

1. Autocrops the image

2. Resizes the image (i.e. increases the canvas size without scaling the image) to make it square. I want this to occur by taking the shorter dimension and expanding it in both directions to make it equal to the length of the larger dimension (e.g. 120 x 80 px image becomes 120 x 120 px image)

3. Scales the image to a pre-defined size (e.g. 500 x 500 px)

So far, the following is the best I've been able to cobble together:

images = gimp.image_list()
layers = images[0].layers
w = gimp.pdb.gimp_image_width(images[0])
h = gimp.pdb.gimp_image_height(images[0])
if w > h:
#This resizes it if it is wide
#This resizes it if it is tall

It wouldn't surprise me if that's a really ineffective way of getting what I want, but I have very little programming experience and no prior experience with Python.

I've been reading over many tutorials and resources on the web and unfortunately, this is as far as I've been able to get over multiple days of frustration.

Ideally I'd like to allow the plugin to prompt the user for a directory and have it perform these three operations on all of the images within. But at this point, I would greatly appreciate any help I can get.


I tried to put what I've written so far into a Python skeleton, and although the plugin registers in GIMP, it does nothing to the image when I use it.
Find all posts by this user
Quote this message in a reply
May 22, 2012, 17:36
Post: #2
RE: Attempting to Write Python Plugin and Failing Miserably
Thanks for your reply!

I made the changes you suggested, and while the plug-in registers properly within GIMP, it fails with an error message when I attempt to use it:

"TypeError: autocropper_plus_function() takes exactly 2 arguments (4 given)"

Here's my script:

#!/usr/bin/env python

from gimpfu import *

def autocropper_plus_function(image,drawable):
    w = image.width
    h = image.height
    if w > h:
        #This resizes it if it is wide
        #This resizes it if it is tall

    "Autocropper Plus",
    "Autocrops the image and then increases the width or height to make it square",
    "Michael Varischetti",
    "Michael Varischetti",
    "May 2012",
    "<Image>/Image/Scripts/Autocropper Plus",
        (PF_IMAGE, "image", "Input image", None),
        (PF_DRAWABLE, "drawable", "Input drawable", None),


I'm assuming two of the arguments are "image" and "drawable" but I don't understand what the other two arguments are and where they are coming from.

Thanks in advance for any additional assistance you're willing to provide.
Find all posts by this user
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Question beautify plugin ! i can not install it! unknown7 3 172 Feb 12, 2018 21:02
Last Post: unknown7
  Separate+ plugin doesn't show NathanD 5 4,355 Jan 28, 2018 20:44
Last Post: janrich
  Any plugin for open multiple image in shinprog 1 474 Oct 31, 2017 11:38
Last Post: paynekj
  plugin save for web in Gimp 2.9.6 Dkk 1 339 Oct 19, 2017 09:02
Last Post: paynekj
  Loading PythonFu Plugin: ImportError for .../python/ (GIMP 2.8.22/OSX/Py2.7.9) joroek 1 504 Jul 11, 2017 07:26
Last Post: ythgilb

Forum Jump:

GIMP ForumPortalArchiveContactTermsRSS