Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Gimp Tutorial
Gimp Introduction
Gimp Background
GIMP PDB
Gimp Object Oriented Syntax
Gimp Painting Areas
Gimp Creating Text
Gimp Floating Selections
Gimp Perl Server

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


The GIMP PDB


Previoushome Next






4. The GIMP PDB


A D V E R T I S E M E N T

Before going into the details of the Perl-Fu script, we will describe how to access the various the functionality of GIMP. All functions known to GIMP are available through the procedural database (PDB). All the PDB functions may be called from perl, as will be seen below. These PDB functions are either internal to gimp, or have been made available through a plug-in or a script extension, but as far as the caller is concerned there is no difference. As we will see below, when a perl function is registered through the register function, it will appear in the PDB as well.

Gimp/perl comes with a PDB browser available in Xtns>PDB Explorer. (There is another PDB browser available in Xtns>DB Browser but the PDB Explorer is more suited for Perl users.) This browser provides a way of seeing all the functions in the PDB, as well as their input and output parameters. E.g. the PDB Explorer entry for gimp_image_new, which will be used in the example below looks like this:

 

Name: gimp_image_new
Blurb: Creates a new Image with the specified with, height, and type
In: INT32 width The width of the image
  INT32 height The height of the image
  INT32 type The type of image { RGB (0), GRAY (1), INDEXED (2)
Out:
  IMAGE image The ID of the newly created image
Help: Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp_display_new' with this image as an argument will fail. Layers can be created using the 'gimp_layer_new' commands. They can be added to an image using the 'gimp_image_add_layer' command

All the the constants mentioned in the PDB Explorer have been defined within Gimp::Fu and may be used within perl. E.g. I.e. a call to create a new image of size 100x150 of type RGB looks as follows:

   $img = gimp_image_new(100, 150, RGB)

The PDB entry above shows that gimp_image_new is called with three parameters width, height, type. These are all of type INT32. This type and other types will be explained below.

Script-Fu scripts are called just like any other script according to the PDB signature in the PDB browser. E.g. to run the Script Fu basic one logo just do:

script_fu_basic1_logo("Hello", 72,
                      "-*-utopia-*-r-*-*-72-*-*-*-*-*-*-*", 
                      [0,0,0],[1,1,1]);

Unfortunately, as of the writing, calling Script Fu from perl has proved a to make both ScriptFu and gimp very unstable and caused both of them to crash. If any of the readers is able to describe what is needed to get it to run successfully, I will happily include this in a future version of this tutorial.

 

Note!

When calling a PDB function from Perl::Gimp that has an image and a drawable as the two first arguments, only the drawable should be given as argument in the calling sequence.


4.1. Gimp::Fu and the register function


Gimp-Fu is perl's answer to Script-Fu. It provides a simplified method for accepting parameters for a script through a Gtk interface, just like script-fu, but as we shall see below, it has some additional bells and whistles.

The main function for a Gimp-Fu script is the register function. This function declares the interface of the script to gimp. The register function takes the following 10 parameters, that must all be provided:

  1. The name of the function - a string. This is the name of the function as it will be known in the PDB.

     

  2. A small description - a string

     

  3. A help text - a string

     

  4. The authors name - a string

     

  5. The copyright of the script - a string

     

  6. Creation date - a string

     

  7. Menu path - a string. The path has one of the two forms:
    1. "<Toolbox>/Xtns/Perl-Fu/Script Name"
    2. "<Image>/Perl-Fu/Script Name"

    If form 1. is given, then the script is a standalone script that appears in the menu hierarchy under Xtns/Perl-Fu and takes all its inputs through the Gimp::Fu interface frame. If form 2. is given on the other hand, then the script is tied to the image menu popped up through the right hand button over any image. In this case Gimp::Fu will add as the first two parameters to the script the image and the drawable active when the script was invoked.

     

  8. The acceptable image types - a string. This list contains a list of image types acceptable. This field is only used for scripts that are in the "<Image>" hieararchy. Possible values are listed in the table below:
    value meaning
    * Any images are accepted
    RGB RGB images
    RGBA RGB images with alpha channels
    GREY Grey level images

     

  9. Parameters - A reference to an array of parameters. (A reference to an array in perl is simply an array written within square brackets). Each parameter in turn is a reference to an array containg the following four or five values:
    1. The type of the parameter. The types recognized by Gimp::Fu and their perl are given in the following table:
      Type Possible forms Comment
      PF_INT
      PF_INT32
      PF_INT16
      PF_INT8
      42 A number. PF_INT is a synonym to PF_INT32.
      PF_VALUE
      PF_FLOAT
      3.141 A floating point number.
      PF_TOGGLE
      PF_BOOLEAN
      0
      1
      A boolean value.
      PF_SLIDER
      PF_SPINNER
      An integer value through a slider and a spinner interface. The range parameter should be specified and is interpreted as minimum, maximum, and step, e.g. [0,100,1].
      PF_FONT -*-blippo-*-*-*-*-24-*-*-*-*-*-*-* A font in X11 font format. This interface launches a font browser.
      PF_STRING "A string" A string
      PF_COLOR
      PF_COLOUR
      [255,127,0]
      #ff7f00
      A color may either be expressed as a reference to an array of three components, or as a hexadecimal triple, proceeded by the hash sign.
      PF_TOGGLE 0
      1
      A boolean toggle
      PF_IMAGE - An image
      PF_DRAWABLE - A drawable.
      PF_BRUSH A brush
      PF_GRADIENT A gradient
      PF_PATTERN A pattern

    2. The name of the parameter - a string
    3. A help text for the parameter
    4. Default value for the parameter. This should be given in the form listed in the table above.
    5. An array defining allowed range for the value. This is only possible for PF_SLIDER and PF_SPINNER.

     

  10. A reference to an array of return types of the sub in the 11th parameter.

     

  11. The sub to be called - a reference to a sub . This subroutine will be called when the associated menu entry declared through the

    Menu path described above. When the sub is called it is passed as arguments the list of parameters declared in field 9, declared above, and in the case of a "<Image>..." script, the active image and layer as first and second parameters.

    A reference to a sub in perl may be declared in two ways. Either by declaring a subroutine at a different place in the source file, e.g. sub run and reference it by writing \&run. An alternative way is to write it inline by simply writing:

        sub { ($text, $color) = @_ ; ... }
    The sub is expected not need to display a new image after it has created it. Instead it is expected to return the new image or images that were created in accordance with the return types declared in parameter 10 of the register call described above. This behaviour has been added in order to be able to call the sub noninteractively. More about that behaviour below.


4.2. A commented script


The following Gimp::Fu script example shows the steps described in the previous section. It registeres a script that takes two values, the size of the image and a color, and then produces an image of the requested size with the requested color. Quite useless, but is shows the importent steps of how to register a script, how to create a new image, and how to access some PDB functions.

 

uni
  1:  #!/usr/local/bin/perl -w 
  2:   
  3:  use Gimp ":auto"; 
  4:  use Gimp::Fu; 
  5:   
  6:  sub img_uni { 
  7:      my ($size, $color) = @_; 
  8:       
  9:      # Create a new image 
 10:      $img = gimp_image_new($size, $size, RGB); 
 11:   
 12:      # Create a new layer 
 13:      $layer = gimp_layer_new($img, $size, $size, RGB, 
 14:  			    "Layer 1", 100, NORMAL_MODE); 
 15:   
 16:      # add the layer to the image 
 17:      gimp_image_add_layer($img, $layer, -1); 
 18:   
 19:      # Set the background to the required color 
 20:      gimp_palette_set_background($color); 
 21:   
 22:      # Paint the layer  
 23:      gimp_edit_fill($layer, BG_IMAGE_FILL); 
 24:   
 25:      # Return the image 
 26:      return $img; 
 27:  } 
 28:   
 29:  register 
 30:      "img_uni",                 # fill in name 
 31:      "Create a uniform image",  # a small description 
 32:      "A tutorial script",       # a help text 
 33:      "Dov Grobgeld",            # Your name 
 34:      "Dov Grobgeld (c)",        # Your copyright 
 35:      "1999-05-14",              # Date 
 36:      "<Toolbox>/Xtns/Perl-Fu/Tutorial/Img Uni",   # menu path 
 37:      "*",                       # Image types 
 38:      [ 
 39:       [PF_INT,   "size", "Img size", 100], 
 40:       [PF_COLOR, "color", "Img color", [255,127,0]] 
 41:      ], 
 42:      \&img_uni; 
 43:   
 44:  exit main(); 


Most of these commands are directly copied out the PDB.  

This script shows the essential steps of producing a stand-alone script:


line(s) Description
10 Creating a new image.
13-14 Creating one or more layers.
17 Attaching the layer to the image.
19-23 Do some painting operations in the layers.
26 Return the image to the caller
29-42 Registration of the extension


To test the script, save it in the directory $HOME/.gimp-1.2/plug-ins. It must then be made executable through the command:
     chmod +x $HOME/.gimp-1.2/plug-ins/uni

Then start gimp. It is generally a good idea to test the syntax of the script with perl -c before starting gimp. (A more official way to add scripts is to use the gimptool --install-bin command).

Note: Due to a bug in gimp (verified for version 1.2) it is not possible to add scripts once gimp is running. On the other hand, it is possible to change a script which has already been registered, as long as the parameters don't change.

The script is now accessible through the menu system through the Xtns top menu:

When choosing this menu entry the following screen is popped up:

 

Choosing the default values result in the image:

 




Be the first one to comment on this page.




  Gimp Tutorial eBooks

No eBooks on Gimp could be found as of now.

 
 Gimp Tutorial FAQs
More Links » »
 
 Gimp Tutorial Interview Questions

No Gimp Interview Questions could be found as of now.

 
 Gimp Tutorial Articles

No Gimp Articles could be found as of now.

 
 Gimp Tutorial News

No News on Gimp could be found as of now.

 
 Gimp Tutorial Jobs

No Gimp Articles could be found as of now.


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: The GIMP PDB, GIMP Tutorial, GIMP tutorial pdf, history of GIMP, basic GIMP, syntax use in GIMP, GIMP training courses, GIMP Download.

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.