Post Reply 

Need help with basic Python script

Jun 7, 2011, 05:08
Post: #1
Need help with basic Python script
Hi all,

I am trying to use gimp at work to view a series of images one by one while working form the command line. So far, I am just experimenting with a basic script:

#!/usr/bin/env python

from gimpfu import *

infile = "gstest.JPG"

image = pdb.gimp_file_load(infile, infile)

display = pdb.gimp_display_new(image)

I am running this form the command line with:
gimp -idf --batch-interpreter python-fu-eval -b execfile test-gimp-python.py -b pdb.gimp_quit

but it keeps giving me
GIMP-Error: Opening '/home/collin/test-gimp-python.py' failed: Unknown file type

I know that for plugins, you need a lot more stuff - registration, etc. I just wanted to be able to run gimp, show an image, maybe zoom in and out if I have to, close the image and look at the next (I'll add the loop later). These steps work from the python console activated in gimp, so I am guessing it is possible to do form the command line. I can't seem to find any simple working examples anywhere. Can someone tell me what I am missing? Do I need all the registry stuff and have to put the script in the plug-ins directory?

Thanks.

-C
Find all posts by this user
Quote this message in a reply
Jun 7, 2011, 06:44
Post: #2
RE: Need help with basic Python script
In your line, yoiu are missing alot of quotes. In particular, test-gimp-python.py is not seen as the value of any dash-parameter, so is asume to be plain filename and loaded as an image.

I've not played often with batch mode but the line I used was:

Code:
gimp-2.6 -idf --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import batch;batch.run("./images")' -b 'pdb.gimp_quit(1)'

You can see I had to play with the python path to make it load the python code (in a batch.py).

IMHO I would anyway take your problem from a different angle: write a regular Gimp python that is used from inside Gimp and that:

- gets the filename of the current image (image.filename)
- saves/closes the current image
- determines algorithmically the name of the next image
- opens it

The "next" algorithm can be the extraction of the numeric part of the filename followed by an incrementation, or list/sort the directory contents, and iterate one past the current filename, or read a list somewhere (using a file parameter).

You start the process by loading the first image "by hand", and then calling the filter to go to the next. You can even assign a keyboard shortcut to the plugin.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 7, 2011, 14:11
Post: #3
RE: Need help with basic Python script
Hi -Thanks for the reply. So I modified my start command:

gimp -idf --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path; execfile("./test-gimp-python.py")' -b 'pdb.gimp_quit(1)'

and I got a lot farther:

(gimp:13808): GLib-WARNING **: goption.c:2132: ignoring no-arg, optional-arg or filename flags (8) on option of type 0
Traceback (most recent call last):
File "/usr/lib/gimp/2.0/python/gimpfu.py", line 771, in _run
return apply(func, params[1:])
File "/usr/lib/gimp/2.0/plug-ins/python-eval.py", line 26, in code_eval
exec code in globals()
File "<string>", line 1, in <module>
File "./test-gimp-python.py", line 9, in <module>
display = pdb.gimp_display_new(image)
RuntimeError: execution error
batch command experienced an execution error

My guess is I can't do exactly what I want to from the command line because when I run the script, gimp (the pieces I am used to - all the windows etc.) is not initialized. I will admit this is my first time trying this - I haven't grasped exactly how it works, what is possible, etc. I think I like your idea better though - I could even make it so the user could create some kind of list or list structure - you could compare multiple images side by side, etc. I can think of a lot of useful little tools to create as "plug-ins". Thanks for your suggestion. I'll give it a shot. When I get it working (which may be a while - I do this in my spare time, which I have little of) I'll let you know the results. thanks again!
Find all posts by this user
Quote this message in a reply
Jun 8, 2011, 14:56
Post: #4
RE: Need help with basic Python script
One thought. Your command line options are not right if you are expecting to see a user interface
see the documentation:
http://docs.gimp.org/2.6/en/gimp-fire-up...mmand-line

You need to remove the "i" from -idf because it's telling GIMP to run without a user interface. This would explain why it errors at pdb.gimp_display_new(image)
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for script chlebna 1 171 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 229 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholomäus 2 230 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 194 Aug 23, 2017 12:48
Last Post: paynekj
  Loading PythonFu Plugin: ImportError for .../python/gimp.so (GIMP 2.8.22/OSX/Py2.7.9) joroek 1 314 Jul 11, 2017 07:26
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS