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
  Run Deskew plugin from Python-Fu console ramonvaldezz 12 3,165 Nov 18, 2018 21:48
Last Post: paynekj
  GIMP Resynthesizer Plugin not working Mikkel Andersen 1 749 Jun 26, 2018 16:36
Last Post: paynekj
  Gimp 2.10 with old vignette from Plugin registry. DenisT 2 583 May 19, 2018 20:42
Last Post: DenisT
  Export Layers Plugin not working with 2.10? Imc7r 2 544 Apr 30, 2018 14:22
Last Post: Imc7r
Question beautify plugin ! i can not install it! unknown7 3 769 Feb 12, 2018 21:02
Last Post: unknown7

Forum Jump:

GIMP ForumPortalArchiveContactTermsRSS