The Quick Start Guide to the GIMP, Part 3
I just got through mentioning the use of layers in conjunction with selections. Layers are like transparencies used for overhead projectors, with the ones on top mixing with layers below to produce the final image. Each layer can be added, subtracted, multiplied, screened, overlayed and have any of a number of other processes applied to it with respect to the layers below it. By default, a new image has one layer—the Background layer. The default for this layer is to be solid white, but it is possible to change this based on the background color and transparency settings.
Layers are accessed via the Layers and Channels dialog box. This dialog is opened from the “Dialog->Layers and Channels” menu option from the pop down menus in the Image Window. Figure 3 shows a sample of the dialog in use. Inside the dialog there are a number of features: an image selection menu, the Close button and a notebook with tabs for choosing either the Layers or the Channels feature. In the Layers page of the notebook there is a menu for selecting the Mode to apply to this layer (such as add, subtract, darken, etc.). It's also possible to apply a uniform transparency level to the current layer using the Opacity slider.
Below the slider there is a window which shows each of the layers for the current image specified in the Image Menu (which is located at the top of the Layers and Channels Dialog). Each layer displayed contains four default fields: visibility, move anchor, a thumbnail preview of the layer and the layer's name. A grayscale mask field is not displayed by default, but can be created by selecting the Add Layer Mask option from the Layer Menu. This menu is opened by clicking the left mouse button over the name of the current layer and is used for all layer specific functions except transparency and mode selection. Double clicking on the layer's name will bring up the Edit Layer Attributes dialog in which you can specify a new name for the layer. Get into the habit of setting the names of layers often, since many of your images may have many small layers; finding the one you want simply by looking at the thumbnail may not be easy. In most cases, changes to an image affect only the currently active layer. The active layer is the highlighted one in the list of layers. On most systems this is a blue highlight, although it's possible this might be some other color on very low-end systems with limited color displays.
A few things to note. First, changing the name of a layer will add an Alpha channel to the layer. There are lots of special tricks you can do with Alpha channels that are beyond the scope of this series, but you should be aware that the Background layer, by default and before you have changed its layer name, has no Alpha channel. Also, the size of the thumbnails can be set to just about any size via an option in the gimprc file. As was mentioned in the first article, you should eventually become familiar with the gimprc file, if you find the default settings are not to your liking. You'll be surprised at how much you can configure in the GIMP.
The visibility icon, an eyeball, is used to turn the layer on or off. If the layer is off, its effects on the visible image in the Image Window are removed. Clicking on the field containing the eyeball will toggle the visibility of the layer. When the visibility is off, the eyeball will not be displayed. The visibility icon will be in the far left side of the currently selected layer, directly beneath the “Opacity” text in the Layers and Channels dialog. If you don't see the eyeball there, click the left mouse button in that area and the eyeball will appear. This may or may not affect the visible image in the Image Window, depending on the contents of that layer and the Mode currently selected.
Often it is useful to move more than one layer at a time, i.e., as a group. By default using the Move Tool (in the Toolbox) will affect only the current layer. Clicking on the second field for a layer, the move anchor will set that layer to move along with any other layers which also have their move anchor set. When the move anchor is set, a fleur icon is displayed. A fleur consists of two double ended arrows, perpendicular to each other. Although actions on an image specifically affect the currently active layer, any layer with its fleur displayed will also be moved when the Move Tool is used on the current layer.
Moving a layer can take a little practice. Some layers, due to the use of transparency, are harder to grab than others because very little of the non-transparent region is actually visible. Other layers, higher in the stacking order, may obscure most of a lower layer. When moving a layer you will find it easiest to first select the Move Tool from the Toolbox. Next, move the cursor over a region in the Image Window that you suspect is part of the layer you wish to move. The cursor should change to the fleur symbol when you are over that region. If you then click on that spot and discover the layer selection has changed to another layer, then stop. Press ctrl-Z to undo any moves you've made, if any. (If you accidently undo something you didn't want to, just use “Edit->Redo” in the Image Window menus or ctrl-R to get it back.) Now turn off the visibility of the higher level layers until the layer you want to move is the highest visible layer. You should now have a better chance to grabbing just the layer you want. If you still have problems, you can turn off the visibility of all the layers, higher and lower levels. Again, all of this takes a little practice.
The list of layers is shown with the topmost layer at the top of the list and the bottom layer, the background layer, at the bottom. When the layers are combined, also know as composited, they are combined from bottom to top. So the bottom layer defines the start of the image's initial appearance before the other layers are combined with it. The Image Window will display the image based on which layers are currently visible. The compositing is done by the GIMP in a way that is invisible to the user except for changes made to the Mode or visibility of a layer. Since the layers are processed from bottom to top, the order of the layers is important. Layers can be raised or lowered using the Layers Menu. The Layers Menu is opened by clicking the left mouse button over the name of a layer. Selecting an option in the Layers Menu only affects the layer over which the menu was opened.
The size of the preview in the Layers and Channels dialog can be set in the gimprc file. Smaller preview sizes do not really speed up processing but do require less memory and allow more layers to be displayed simultaneously. Layers themselves are not constrained to the same size, although when producing the final image, a constraint of some kind will be applied to all layers. The constraint used depends on the way the final image is produced from the layers.
Layers provide tremendous flexibility in producing images in the GIMP, but they can cause a little confusion when first starting out. It is important to note the following about layers when saving or loading images:
New images have a single, white background layer.
Opening an existing file in any format except XCF will load the image into the background layer. You cannot open an image into a layer of an existing Image Window. If you want to do this, you need to open the image in a new window, select the entire image (ctrl-A in the Image Window), copy it (“Edit->Copy”) and then paste it (“Edit->Paste”) into the existing Image Window.
Saving an image in any format except XCF will save only the currently active layer. If there is more than one layer and you want to save the image visible in the Image Window to GIF, JPEG or some other format, you should first flatten the layers and then save the image.
Saving an image with layers using the XCF format will save the image while preserving all the layer information.
The XCF format is the native file format for the GIMP and you should save all work in progress in this format. This format will necessarily produce very large files, much larger than the other file formats available. When you are done working on an image and ready to produce the final image into one of the many image file formats supported, you need to merge all the visible layers or flatten the image. The latter process will remove transparency layers (after processing them) and constrain the final image to the visible size of the image. The former is similar, but preserves transparency and can be constrained to the actual image size, the size of the bottom layer or can be expanded as needed.
Flattening an image takes all the layers and combines them in a way that matches what you can see visually in the Image Window. Merging the layers can expand the image to encompass non-visible portions of some layers. In most cases, I've found flattening works better for my work. Merging can leave unwanted transparent regions that get translated to black or other colors in GIF or JPEG images. This doesn't mean there aren't any uses for merging, but initially, you'll probably find flattening works best.
There are actually two kinds of layers: normal and floating. A floating layer is a temporary layer that holds a pasted selection prior to applying it to either a new layer or anchoring it in the currently active layer. Floating layers have a few limitations due to their transient nature. Just be certain to convert the floating layer to either a new layer or anchor it by using the appropriate selection from the Layers Menu. Anchoring a floating layer causes it to be composited with the currently active layer or layer mask.
A layer mask is a tool for constraining which parts of a layer should be used in the composited image. This is best shown with a simple example. Let's start with a background layer with a simple gradient applied (Figure 4). Next, add a new layer (via the Layers Menu—click over the layer name with the left mouse button) and apply a different gradient. Then, add the layer mask by opening the Layers Menu and selecting Add Layer Mask. Make the layer mask fully transparent by selecting the Black toggle in the Add Mask Options dialog box. Make sure the new layer is the active layer by clicking on its preview image. The image state should look similar to Figure 5.
Now open a new image, a TIFF file that is a black and white image of a leaf (Figure 6). The leaf is white with a black background so that it will allow the current layer to show up in the interior of the leaf (the white areas) and allow the rest of the image to be transparent (allowing the first gradient to show through). Then select the entire leaf's image using “Select->By Color” and copy it to the clip buffer using the Image Windows menus (“Edit->Copy”). Paste that into the gradient layer and anchor it. The pasted image becomes part of the layers mask.
Note that you can set whether a floating layer is anchored to the main layer image or to the layer mask by clicking on the preview images in the Layers and Channels dialog. The outline of the preview image is highlighted to show which part of the layer will be used to anchor the pasted image.
Now the image has two layers, with two different gradients applied. The top layers gradient only shows up where the leaf's mask is white. Figure 7 shows the final image with the Layers and Channels dialog.
You can turn the layers mask on and off by holding down the control (ctrl) key while clicking the left mouse button in the masks preview image for the active layer. Alternatively, you can view just the mask by holding down the alt key and left-button clicking in the masks preview image. In the former case, visibility turned off creates a red border around the layers mask preview. In the latter case, visibility of the actual layer creates a green border. I don't use this feature much yet, but it's nice to know it exists.
The Layers Menu provides an Apply Layer Mask option which will composite the mask with the layer, if accepted. The same option provides the ability to discard the layers mask, in which case the mask is removed and no longer affects the layer or the composited image. You will need to apply the layer mask if you wish to use some filters or effects from the Image options in the Image Window menus.
- Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs
- Tech Tip: Really Simple HTTP Server with Python
- New Products
- Returning Values from Bash Functions
- EdgeRouter Lite
- Non-Linux FOSS: Remember Burning ISOs?
- RSS Feeds
- Cooking with Linux - Serious Cool, Sysadmin Style!