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
  Wich plugin cold help me ? Alexandra 1 86 May 14, 2019 08:27
Last Post: paynekj
  How to install Gimp Heal Plugin (Linux)? ciararseeley 2 273 Mar 20, 2019 09:19
Last Post: paynekj
  Problem with the Twain Scanner Plugin klgrube 1 621 Feb 5, 2019 09:03
Last Post: paynekj
  python-fu file_dds_save wrong number of paramters ? Thial 1 855 Jan 14, 2019 09:28
Last Post: paynekj
  Run Deskew plugin from Python-Fu console ramonvaldezz 12 3,766 Nov 18, 2018 21:48
Last Post: paynekj

Forum Jump:

GIMP ForumPortalArchiveContactTermsRSS