GIMP Usage: Difference between revisions

From Elvanör's Technical Wiki
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Interface ==
= Interface =


* If you run the GIMP under KDE, start it in a new desktop: that's currently the only way I found to get all the GIMP windows to reappear when working with multiple applications.
* If you run the GIMP under KDE, start it in a new desktop: that's currently the only way I found to get all the GIMP windows to reappear when working with multiple applications.
* All tools have simple key shortcuts that are very useful, try to remember them.
* All tools have simple key shortcuts that are very useful, try to remember them.


== Saving ==
= Saving =


* PNG format allows you to choose the compression level. The default maximal compression level acts strangely (artifacts on the image), so if that happens reduce the compression level to 5-6.
* PNG format allows you to choose the compression level. The default maximal compression level acts strangely (artifacts on the image), so if that happens reduce the compression level to 5-6.
Line 14: Line 14:
* Saving in XCF format (or any other format) loses all your history / undo information, so be careful.
* Saving in XCF format (or any other format) loses all your history / undo information, so be careful.


== Selection ==
== Exporting for the Web ==
 
* Firefox and other browsers apply overlays (a block with a color and an opacity) in a way incompatible with Gimp. The solution is to make sure in Gimp that there are no partially transparent pixels (eg, all the alphas are set to 100%). Else it can lead to subtle differences that will be visible.
 
= Selection =


* When making a selection, for example with the rectangle tool, you have to confirm it by clicking on it. Until this click, the selection is easily modifiable by using the sub-rectangles appearing  
* When making a selection, for example with the rectangle tool, you have to confirm it by clicking on it. Until this click, the selection is easily modifiable by using the sub-rectangles appearing  
* A selection also usually shows the layer boundaries (which is a good thing).
* A selection also usually shows the layer boundaries (which is a good thing).
* You can create a new selection based on a layer "contents" (parts that are not transparent). This is done by right-clicking on the layer and choosing "Alpha to selection".
* You can create a new selection based on a layer "contents" (parts that are not transparent). This is done by right-clicking on the layer and choosing "Alpha to selection".
* If you create a anti-aliased selection, this will apply to future operations. For example, a fill on an anti aliased rectangle will not fill uniformly the rectangle with the color; the edges will get a smooth transition.
* If you create a anti-aliased selection, this will apply to future operations. For example, a fill on an anti-aliased rectangle will not fill uniformly the rectangle with the color; the edges will get a smooth transition.
* Showing grids (and activating "Snap to Grid") will greatly help with the creation of rectangles, exact circles, etc. If you want to create a shape, the best is to save a temporary selection to a path, then add or remove new selections to this path.
* Showing grids (and activating "Snap to Grid") will greatly help with the creation of rectangles, exact circles, etc. If you want to create a shape, the best is to save a temporary selection to a path, then add or remove new selections to this path.
* There is a shortcut for clearing the selection, which can be very handy.
* There is a shortcut for clearing the selection, which can be very handy.


== Gradients ==
== Selections as masks ==
 
* In Gimp, a selection does not contain selected pixels and unselected ones. Pixels can be partially selected; usually most selection tools will create antialiased selections. This effects operations such as the paint tool and so on. It is best to think of the selection as a mask with multiple possible values. It's not a binary mask.
 
* To get a "binary selection", use Selection->Sharpen command.
 
= Gradients =


* One useful gradient is the FG to Transparent one. With it you can create glossy effects easily (picking white as foreground color).  
* One useful gradient is the FG to Transparent one. With it you can create glossy effects easily (picking white as foreground color).  


== Colors ==
= Colors =


* Some color operations (like color balance) won't work on desaturated components (black or white parts of the layer).
* Some color operations (like color balance) won't work on desaturated components (black or white parts of the layer).


== Layers ==
= Layers =
 
== General ==


* To copy a layer from an image to another one, you can drag and drop it from the old image to the new one. You can also do a copy and paste (but then you need to anchor the new selection that you just pasted - this will create a new layer).
* To copy a layer from an image to another one, you can drag and drop it from the old image to the new one. You can also do a copy and paste (but then you need to anchor the new selection that you just pasted - this will create a new layer).
Line 43: Line 55:
* You can obtain the size of a text layer bounding box programmatically by calling gimp-text-get-extents-fontname. This won't actually create the layer.
* You can obtain the size of a text layer bounding box programmatically by calling gimp-text-get-extents-fontname. This won't actually create the layer.


== Tools ==
== Layer Masks ==


* The bucket fill tool, called via the PDB interface, does not seem to work without a selection, so make a selection first. If it is a newly created layer that you want to fill entirely, it is better to use:
* Layer masks represent the opacity of the layer. Layer masks have their color values coded in gray tones (256 I think). White means full opacity, black means deletion (full transparency). Using layer masks you can for example easily create a fading effect. Just create a layer mask (initialized to white), paint in black the area you want to remove, and use a gaussian blur to make a smooth transition.


pdb.gimp_drawable_fill(layer, FOREGROUND_FILL)
* One common effect is to select all the image, shrink it by a certain amount, invert the selection and then paint the selection in black before blurring it.


== Scripting ==
= Tools =


* Scripting the GIMP can be done easily using the Python API. You can write pure Python scripts, and you don't need to use Scheme at all.
* The bucket fill tool, called via the PDB interface, does not seem to work without a selection, so make a selection first. If it is a newly created layer that you want to fill entirely, it is better to use:


* In order to make your Python script accessible from within the GIMP, you need to save it in ~/.gimp-2.4/plug-ins/. You need to make it executable or GIMP won't recognize it.
  pdb.gimp_drawable_fill(layer, FOREGROUND_FILL)
 
* In your script, you need to have the register() function and a main() function which can be empty, in addition to your actual function which executes what you want. Here are the arguments for the register function (with an example):
** "generate_rounded_corners": Name of the plugin (how to call it programmatically with Script-Fu)
** "This is a test Python plugin." : Textual description
** "It creates and saves an image.": Other description (extended, not sure here)
** "Elvanör": Author
** "Jean-Noël Rivasseau": Copyright owner
** "2007": Date
** "_Rounded Corners...": Name of the plugin (in the GIMP menus)
** "RGB*, GRAY*": Modes accepted (??)
** []: Arguments to this plugin
** []: Return values of this plugin, only useful in non interactive mode
** generateRoundedCorners: Python callback function (essential!)
** menu="<Image>/Filters/Render/Rounder Corners": Path in the menus
 
* In the previous list, the arguments list has the following syntax:
** PF_STRING: type of argument
** "targetDirectory": argument name
** "The directory in which will be saved the images": description
** "/srv/": Default value. This is used *only* in the interface, eg. when using the plugin non interactively you must always pass the correct number of arguments.
 
* The _() function that you can see used in example plug-ins is for internationalization. The "_R" in "_Rounded Corners..." is for the mnemonic, eg the key that will be associated as a shortcut in the interface.
 
== Developing Python Scripts ==
 
* You can make your image appear on the GUI with the following command:
 
  display = pdb.gimp_display_new(image)
 
* A recommended way to debug your scripts is to run each command separately in the Python console. You can also exit from a Python script by using the return() statement.
 
* A primitive way to get basic information displayed by your scripts is to use the gimp_message function, which will display a string on the GIMP's GUI.
 
== Python API / Bindings ==
 
* For operations on a layer, you must add the layer to the image first. Else you will get an execution error.
 
* In the PDB, some functions like pdb.gimp_text_fontname allows to specify -1 as a DRAWABLE argument (to create a new layer). Using the Python API this does not work, and should be replaced with None.
 
* You can obtain built-in documentation about the API by using dir (gimp) in the Python Gimp shell. You should import gimpfu first.
 
* Another way is to use help() on a defined variable, for example a layer.
 
== List of types in Python ==
 
* PF_INT8        = PDB_INT8
* PF_INT16      = PDB_INT16
* PF_INT32      = PDB_INT32
* PF_INT        = PF_INT32
* PF_FLOAT      = PDB_FLOAT
* PF_STRING      = PDB_STRING
* PF_VALUE      = PF_STRING
* PF_COLOR      = PDB_COLOR
* PF_COLOUR      = PF_COLOR
* PF_REGION      = PDB_REGION
* PF_DISPLAY    = PDB_DISPLAY
* PF_IMAGE      = PDB_IMAGE
* PF_LAYER      = PDB_LAYER
* PF_CHANNEL    = PDB_CHANNEL
* PF_DRAWABLE    = PDB_DRAWABLE
* PF_VECTORS    = PDB_VECTORS
* PF_TOGGLE      = 1000
* PF_BOOL        = PF_TOGGLE
* PF_SLIDER      = 1001
* PF_SPINNER    = 1002
* PF_ADJUSTMENT  = PF_SPINNER
* PF_FONT        = 1003
* PF_FILE        = 1004
* PF_BRUSH      = 1005
* PF_PATTERN    = 1006
* PF_GRADIENT    = 1007
* PF_RADIO      = 1008
* PF_TEXT        = 1009
* PF_PALETTE    = 1010
* PF_FILENAME    = 1011
* PF_DIRNAME    = 1012
 
Obsolete:
 
* #PF_INT8ARRAY  = PDB_INT8ARRAY
* #PF_INT16ARRAY  = PDB_INT16ARRAY
* #PF_INT32ARRAY  = PDB_INT32ARRAY
* #PF_INTARRAY    = PF_INT32ARRAY
* #PF_FLOATARRAY  = PDB_FLOATARRAY
* #PF_STRINGARRAY = PDB_STRINGARRAY
* #PF_SELECTION  = PDB_SELECTION
* #PF_BOUNDARY    = PDB_BOUNDARY
* #PF_PATH        = PDB_PATH
* #PF_STATUS      = PDB_STATUS
 
* Note that you cannot currently pass an array to a Python Gimp script, since PF_STRINGARRAY has been removed ([http://bugzilla.gnome.org/show_bug.cgi?id=122049 see this bug for reference]). One workaround is to pass a string with special separators (like slashes), and split it into an array inside the Python code.
 
== Launching GIMP from outside ==


* When loading GIMP with gimp-console for example, it will load an interpreter (the default is the Script-Fu one - but you can change that to the Python one if you want). This interpreter will then execute commands given to it (via the -b command line option for example).
* There is an align tool that allows you to precisely move objects (enter their positions with numerical values). Unfortunately, the units are always in pixels which can be troublesome.


* If you call Gimp from Java (via an external process), don't surround the Script-fu commands with single quotes. These are only needed if you launch Gimp from the shell, so that Gimp knows it's a string. If you use them in Java, it won't work since you will pass a string to script-fu rather than a command (Bash did not act the same way).
= [[GIMP Scripting]] =

Latest revision as of 11:21, 29 September 2010

Interface

  • If you run the GIMP under KDE, start it in a new desktop: that's currently the only way I found to get all the GIMP windows to reappear when working with multiple applications.
  • All tools have simple key shortcuts that are very useful, try to remember them.

Saving

  • PNG format allows you to choose the compression level. The default maximal compression level acts strangely (artifacts on the image), so if that happens reduce the compression level to 5-6.
  • Saving in PNG format from within a Python script has a risk of croping the image to the layer boundary. To avoid this, just resize the layer to the image first like this:
pdb.gimp_layer_resize_to_image_size(finalLayer)
  • Saving in XCF format (or any other format) loses all your history / undo information, so be careful.

Exporting for the Web

  • Firefox and other browsers apply overlays (a block with a color and an opacity) in a way incompatible with Gimp. The solution is to make sure in Gimp that there are no partially transparent pixels (eg, all the alphas are set to 100%). Else it can lead to subtle differences that will be visible.

Selection

  • When making a selection, for example with the rectangle tool, you have to confirm it by clicking on it. Until this click, the selection is easily modifiable by using the sub-rectangles appearing
  • A selection also usually shows the layer boundaries (which is a good thing).
  • You can create a new selection based on a layer "contents" (parts that are not transparent). This is done by right-clicking on the layer and choosing "Alpha to selection".
  • If you create a anti-aliased selection, this will apply to future operations. For example, a fill on an anti-aliased rectangle will not fill uniformly the rectangle with the color; the edges will get a smooth transition.
  • Showing grids (and activating "Snap to Grid") will greatly help with the creation of rectangles, exact circles, etc. If you want to create a shape, the best is to save a temporary selection to a path, then add or remove new selections to this path.
  • There is a shortcut for clearing the selection, which can be very handy.

Selections as masks

  • In Gimp, a selection does not contain selected pixels and unselected ones. Pixels can be partially selected; usually most selection tools will create antialiased selections. This effects operations such as the paint tool and so on. It is best to think of the selection as a mask with multiple possible values. It's not a binary mask.
  • To get a "binary selection", use Selection->Sharpen command.

Gradients

  • One useful gradient is the FG to Transparent one. With it you can create glossy effects easily (picking white as foreground color).

Colors

  • Some color operations (like color balance) won't work on desaturated components (black or white parts of the layer).

Layers

General

  • To copy a layer from an image to another one, you can drag and drop it from the old image to the new one. You can also do a copy and paste (but then you need to anchor the new selection that you just pasted - this will create a new layer).
  • You can obtain a layer offset with the attribute myLayer.offsets (which is a Python tuple). You can move the layer by setting the offset with the set_offsets method.
  • An layer with the overlay type will modify the color of other layers beneath. Usually for the effect to work you must have a white background or layer below. One solution if you need a transparent background is to just duplicate the elements for which you need the overlay effect applied, and paint the copy in white (keeping alpha values intact).

Text Layers

  • You can obtain the size of a text layer bounding box programmatically by calling gimp-text-get-extents-fontname. This won't actually create the layer.

Layer Masks

  • Layer masks represent the opacity of the layer. Layer masks have their color values coded in gray tones (256 I think). White means full opacity, black means deletion (full transparency). Using layer masks you can for example easily create a fading effect. Just create a layer mask (initialized to white), paint in black the area you want to remove, and use a gaussian blur to make a smooth transition.
  • One common effect is to select all the image, shrink it by a certain amount, invert the selection and then paint the selection in black before blurring it.

Tools

  • The bucket fill tool, called via the PDB interface, does not seem to work without a selection, so make a selection first. If it is a newly created layer that you want to fill entirely, it is better to use:
pdb.gimp_drawable_fill(layer, FOREGROUND_FILL)
  • There is an align tool that allows you to precisely move objects (enter their positions with numerical values). Unfortunately, the units are always in pixels which can be troublesome.

GIMP Scripting