Post Reply 

Run a simple python script

Jul 18, 2011, 21:19 (This post was last modified: Jul 18, 2011 21:21 by jedi200582.)
Post: #1
Run a simple python script
Hello all,
I am a newb. And I realize the pb I have is trivial, but not much people are posting on that on internet.
I have this simple script python-fu script that resizes image in batch mode:

#################################################
#!/usr/bin/python

from gimpfu import *

def plugin_main(timg, tdrawable, neww=620, newh=880):
pdb.gimp_image_scale(timg, neww, newh)
pdb.file_bmp_save(timg, tdrawable, timg.name+"_"+str(newh)+"_"+str(neww)+".bmp",
timg.name+"_"+str(newh)+"_"+str(neww)+".bmp")

register(
"gimp_resize",
"Resizes the image at a specific width and height, and store it to bmp",
"Resizes the image at a specific width and height, and store it to bmp",
"toto",
"toto",
"2011",
"<Image>/Image/Batch resize...",
"RGB*, GRAY*",
[
(PF_INT, "new_width", "New Width", 620),
(PF_INT, "new_height", "New Height", 880),
],
[],
plugin_main)

main()
#################################################

I moved it to my ~/.gimp-2.6/plug-ins.
Now, when in try to run it in command line, it fails:

*******************************************************************************
toto@titi:~/projects/python/img/master$ gimp --verbose -i -b '(python-fu-gimp-resize RUN-NONINTERACTIVE "some_file.xcf" 141 200)' -b '(gimp-quit 0)'

(gimp:16135): GLib-WARNING **: /build/buildd/glib2.0-2.28.6/./glib/goption.c:2132: ignoring no-arg, optional-arg or filename flags (8) on option of type 0
INIT: gimp_load_config
Parsing '/home/jedi/.gimp-2.6/unitrc'
Parsing '/etc/gimp/2.0/gimprc'
Parsing '/home/jedi/.gimp-2.6/gimprc'
gimp_composite: use=yes, verbose=no
Processor instruction sets: +mmx +sse +sse2 -3dnow -altivec -vis
INIT: gimp_initialize
INIT: gimp_real_initialize
INIT: gimp_restore
Parsing '/home/jedi/.gimp-2.6/parasiterc'
Loading 'brush factory' data
Loading 'pattern factory' data
Loading 'palette factory' data
Loading 'gradient factory' data
Loading fonts
Parsing '/home/jedi/.gimp-2.6/templaterc'
INIT: gimp_real_restore
Parsing '/home/jedi/.gimp-2.6/pluginrc'
Starting extension: 'extension-script-fu'
No batch interpreter specified, using the default 'plug-in-script-fu-eval'.
batch command experienced an execution error
EXIT: gimp_exit
EXIT: gimp_real_exit
Terminating plug-in: '/usr/lib/gimp/2.0/plug-ins/script-fu'
Terminating plug-in: '/usr/lib/gimp/2.0/plug-ins/script-fu'
Writing '/home/jedi/.gimp-2.6/templaterc'
Writing '/home/jedi/.gimp-2.6/parasiterc'
Writing '/home/jedi/.gimp-2.6/unitrc'
EXIT: batch_exit_after_callback
********************************************************************************​*

Obviously, I tried many names and options (with - or _, with or without the "python-fu" prefix in the procedure name, with or without the "RUN_NONINTERATIVE" flag....) The debug message is actually not very helpful.

Please help Sad
Find all posts by this user
Quote this message in a reply
Jul 19, 2011, 20:52
Post: #2
RE: Run a simple python script
Thanks for your help both of you,
But without proper documentation and easy way to debug the script, gimp is not useful tool for what I want to do.

Thanks anyway,
cheers.
Find all posts by this user
Quote this message in a reply
Jul 20, 2011, 11:08
Post: #3
RE: Run a simple python script
The thing is I have lot of xcf images. I want to create bitmap version of those, with various sizes (developing something on android and I need different version of the files for small phones, big phones, tablets, etc...).
The problem with ImageMagick is that it only reads one of the layer at a time and produce a bmp file for each layer, instead of combining those. I could solve this issue by removing the alpha channel from the layer (cause I basically have one text layer in my image) but if I do that, I can't modify the text layer anymore, because if I do, the layer is all screwed up.

Anyway, thanks for your help ofnuts.

(Jul 19, 2011 21:59)ofnuts Wrote:  The only good reason to use Gimp in batch mode is because something you want to do on many images only exists as a Gimp filter. When you have read the doc for ImageMagick and seen what it can do, using Gimp batch becomes awfully rare.

For instance, creating a thumb-$n file for every JPG in the current directory, with a small side of 200 pixels:

Code:
convert *.jpg -geometry 200x200^ -set filename:out "thumb-%f" '%[filename:out]'
Find all posts by this user
Quote this message in a reply
Jul 20, 2011, 11:10
Post: #4
RE: Run a simple python script
Yes I did that, and my script works in the console, not in command line. Don't ask me why, I just have this cryptic error message. For what I know, it could be anything...

The documendation is not really helpful either. It does not even mention the error message.

(Jul 19, 2011 21:48)paynekj Wrote:  I grant you that debugging batch scripts isn't easy because of the lack of error messages, so I always start by making an interactive version first.

The official Gimp Python page is a good place to start learning:
http://www.gimp.org/docs/python/index.html
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Run script on action rchav 2 813 Aug 13, 2018 14:57
Last Post: rchav
  Script Fu Errors Gimp 2.10.4 lightsaber jd3481 1 523 Aug 2, 2018 05:13
Last Post: paynekj
  Script-fu script to conversion pdf to image 4ever 12 10,977 Jul 17, 2018 16:01
Last Post: paynekj
  Problems with a bat script :( ThaUnknown_ 1 509 Mar 26, 2018 21:14
Last Post: paynekj
  Script-fu ordered file list vnicent 1 327 Mar 19, 2018 17:33
Last Post: paynekj

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS