Results 1 to 2 of 2
  1. #1
    Member Skottish's Avatar
    Join Date
    Oct 2004
    Location
    Here and Now
    Posts
    902

    Gimp-Python batch how-to

    There is a new version of Script-Fu that was released with Gimp 2.3.13. This new version is based on TinyScheme which is much more standards compliant than the old SIOD interpreter. Large numbers of scripts that use to work in the old Script-Fu will no longer function in the current version because of this. The official website for Gimp batch processing has been updated to reflect these changes:

    http://www.gimp.org/tutorials/Basic_Batch/

    The problem is that the new version adds little to nothing in terms of debugging output, readability, or the availability of relevant documentation.

    One alternative is to use Python, which is very well documented and much easier to read. (See http://www.gimp.org/docs/python/index.html for more information on using Python with Gimp) And with the Python-Fu console in Gimp, getting information on function calls is as simple as it is with Script-Fu. The code below is converted directly from the sample in the former link:

    Code:
    #! /usr/bin/env python
    
    from gimpfu import *
    import glob
    
    def batch_unsharp_mask( file_pattern, radius, amount, threshold ):
    
    	file_list=glob.glob(file_pattern)
    	file_list.sort()
    	for file_name in file_list:
    
    		image = pdb.gimp_file_load(file_name, file_name)
        		drawable = pdb.gimp_image_get_active_layer(image)
    
    		pdb.plug_in_unsharp_mask(image, drawable, radius, amount, threshold)
    
    		pdb.gimp_file_save(image, drawable, file_name, file_name)
    
    		pdb.gimp_image_delete(image)
    
    
    register(
    	"batch_unsharp_mask", "", "", "", "", "",
      	"<Toolbox>/Xtns/Languages/Python-Fu/Test/_Batch Unsharp Mask", "",
      	[
      	(PF_STRING, "file_pattern", "file_pattern", "*.png"),
      	(PF_FLOAT, "radius", "Radius", 5.0 ),
      	(PF_FLOAT, "amount", "Amount", 0.5 ),
    	(PF_INT32, "threshold", "Threshold", 0 )	
      ],
      [],
      batch_unsharp_mask
      )
    
    main()
    Here's an example call to the above code from the console. It will read in all .xcf files in the current directory and apply unsharpmask using the specified values:
    Code:
     gimp -ibdf '(python-fu-batch-unsharp-mask RUN-NONINTERACTIVE "*.xcf" 5.0 0.5 0)''(gimp-quit 1)'
    That's it! Enjoy.
    Last edited by Skottish; 15-Dec-06 at 20:49.



  2. #2
    Member Skottish's Avatar
    Join Date
    Oct 2004
    Location
    Here and Now
    Posts
    902
    Bump to give Google search a thread to lock on to.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •