Chapter 9. Manipulating Images With GIMP

You can use the GNU Image Manipulation Program (GIMP) to create, alter, manipulate, and enhance digital image files -- photographs, scanned images, computer-generated images, and more. This chapter is intended to give you a quick overview of the GIMP and its more common applications.

Like other fields, image manipulation has its own vocabulary. This chapter cannot possibly provide complete documentation for all of the terms and concepts needed to completely understand the GIMP. If you want to learn more, a variety of books are available which document the GIMP and its capabilities, as well as the background concepts of image manipulation. Please refer to the section called Additional Resources if you need more information about the GIMP.

If you cannot create the right effect with the tools that the GIMP provides, and you are not afraid to write scripts in the Scheme scripting language, you can add a new Script-Fu to the GIMP. A Script-Fu is somewhat analogous to a macro in a word processing or spreadsheet application; it applies a set series of effects (filters or other GIMP capabilities) to a graphic or piece of text. Anyone can use the pre-written Script-Fus included with the GIMP, but you can also write your own. See the section called Additional Resources for more sources of information about Script-Fus.

The GIMP can do a lot of things, but it has some limitations. Graphic artists who create images for print media may find the GIMP lacking, or just more difficult to use, for pre-press applications.

For example, the GIMP cannot (yet) work in the CMYK (cyan, magenta, yellow, and black) colorspace, which is generally used for printing color graphics. The GIMP instead uses the RGB (red, green, and blue) colorspace, which should be familiar to people who have created graphics for the Web.

Since the GIMP is well-suited for creating graphics for the Web, that is what we are going to do in this chapter. First, we will edit a photo for display on a Web page. Then we will create a background image, which will be tiled on the background of our Web page. Finally, we will use the GIMP to create a title image for the Web page.

Before we start, you will need to know some basics: how to create and save files, and how to use the Toolbox and Dialogs.

GIMP Basics

To use the GIMP, you will need to know some of the basics. From a shell prompt, you start the GIMP using the command gimp. Start the Gimp in GNOME by going to Main Menu => Programs => Graphics => The GIMP. In KDE, go to Main Menu => Graphics => The GIMP.

Like many applications, the GIMP provides more than one method to accomplish tasks. Generally, there are three ways to work in the GIMP:

When you start the GIMP, you will see the Toolbox.

The Toolbox

The GIMP Toolbox is a palette of commonly used GIMP tools:

Figure 9-1. The Toolbox

You can minimize the Toolbox (send it to the panel), but if you close the Toolbox, you are closing the GIMP.

If you move your mouse over the individual buttons in the Toolbox, a pop-up dialog will appear to identify the tool's purpose.

Click on the button for the tool you want to use in the Toolbox. The button will then appear recessed, to indicate that it is the active tool. The GIMP provides tools that will crop, zoom, erase, smudge, draw, measure, blur, and more.

Generally, you use a tool on an image by activating the tool and then clicking and dragging on your image. If a portion of the image is selected, then the tool will only work on the selected portion. Selections are identified by a moving dotted-line border, called "marching ants."

Many of the tools have options. Double-clicking on the tool's button will display the Tool Options dialog for that tool.

Tools in the Toolbox

Select rectangular regions

This tool is used to select rectangular portions of an image. If you click on the image, then press and hold [Shift] while you are dragging, the rectangle will be a square. If you click on the image, then press and hold [Ctrl] while you are dragging, your starting area will be the center of the rectangle (normally the starting point is at an edge of the rectangle).

Select elliptical regions

This tools is used to select circular or oval portions of an image. If you click on the image, then press and hold [Shift] while you are dragging, the ellipse will be a circle. If you click on the image, then press and hold [Ctrl] while you are dragging, your starting point will be the center of the ellipse (normally, your starting point is at an edge of the ellipse).

Select hand-drawn regions

This tool, also known as the lasso, is used to draw a freehand selection. Click and drag to draw a selection. When you get back to where you started, release the mouse button.

Select contiguous regions

This tool, also known as the fuzzy selection tool or magic wand, is used to select portions of an image based on color values. When you click once on an image with the magic wand active, contiguous pixels with color values close to that pixel will be selected. If you click and drag the magic wand, a larger group of pixels will be used as the starting point.

Select regions using Bezier curves

This selection tool is similar to the freehand select tool, but it allows you to customize your selection. If you need to be very precise when you are selecting a complicated object, the Bezier tool is probably the right choice for the job.

To create a Bezier selection, click to create control points in a connect-the-dots pattern around your selection. Put a control point at every corner or angle of your selection. Click on the first control point you created to close the selection. Now you can move the control points and create curves between them to modify your selection.

To move control points, hold down the [Ctrl] key and drag the point you want to move.

To create curves, click and drag on a control point. As you drag away from the control point, you will see handles appear. Click and drag on the handles to control the shape of the curve.

If you only want to affect the curve on one side of a control point, hold down the [Shift] key and drag on one of the handles.

Once you have finished modifying the Bezier selection, click inside the selection to activate it.

Select shapes from image

The Select shapes from image tool (or intelligent scissors) is intended to improve upon your selection and automatically select the correct shape. This tool occasionally behaves unpredictably, but give it a try. Obviously, this type of selection is easier for the GIMP to handle if the area that you want to select has a distinct edge.

Click on the intelligent scissors tool in the toolbox to activate it. Then, as if you were using the Bezier tool, click on the image to draw a connect-the-dots pattern around your intended selection. The intelligent scissors tool will try to guess what you are selecting, so the lines it draws between the control points will (hopefully) follow the edge of your selection instead of being straight lines between the dots. Click on the first point to complete the selection.

To refine your selection, you can move the control points by clicking on one and dragging. Once you are happy with the selection, click inside it to activate it.

Move layers and selections

The move tool is used to move a selected region.

Immediately after you have created an active selection, if you move your mouse cursor over it, you will see the mouse cursor turn into the move symbol. Click and drag on the selection to move it. This technique works even if the move tool is not activated in the Toolbox.

With the move tool activated, if you click and drag on your image, you will move the entire image (or the active layer). With the move tool activated, if you press [Alt] and then use the arrow keys, you can move the currently active selection outline, one pixel at a time.

Zoom in & out

Also called the magnifying glass, the zoom tool is used to enlarge (by clicking) or reduce (by [Ctrl]-clicking) the image. You can also click and drag to zoom in on a specific region in the image.

Alternatively, the [=] key on your keyboard will zoom in and [-] will zoom out.

Crop the image

The crop tool, which resembles a scalpel, is used to cut away portions of an image. Click and drag to draw a rectangular selection that you want to keep. The Crop & Resize Information dialog will appear. Click on the Crop button on the Crop & Resize Information dialog to remove everything outside the selection. Alternatively, click on the From Selection button on the Crop Selection dialog to make a customizable crop box appear on the image. The control squares at the corners of the box can then be individually moved to refine the crop selection.

Transform the layer or selection

The transform tool can be used to rotate, scale, shear, or change the perspective of an image or selection. Double-click on the Transform button to display the Transform Tool dialog. Choose which action you want to perform on the image or selection. Move the mouse cursor over the selection or image and you will see the mouse cursor change into the transform tool circular arrows icon. Then click and drag on the image or selection to perform the action that you have chosen.

Flip the layer or selection

The flip tool is used to flip (or produce a mirror image) of an image or selection.

Add text to the image

The text tool is used to add text to the image. Select the text tool and then click on the image. The Text Tool dialog will appear. Set the parameters for the text you want to add, type your words into the field at the bottom of the dialog, and click on OK to add the text. Please note that the fonts displayed by the GIMP are the fonts that are accessible to X on your system.

When you add text to an image, the text becomes the active selection. If you move your mouse cursor over the text, you will see the move icon, and you can click and drag to move the text to an appropriate spot on the image.

Pick colors from the image

The color picker is used to choose a color from the image. The Color Picker dialog will display the individual RGB values and the hexadecimal value for the selected pixel. Additionally, the active color box at the bottom of the Toolbox will change to the value of the chosen pixel.

Fill with a color or pattern

The bucket or bucket fill tool is used to fill a selection with the active color or with a pattern.

Fill with a color gradient

The blend or gradient tool is used to fill a selection with a range of colors.

To add a gradient to a selection, first double-click on the gradient button to display the gradient Tool Options. The Blend pulldown menu sets the range of colors to apply. You can blend from the foreground color to the background color or vice versa, you can blend from a color to transparency, or you can choose from the many custom gradients available in the GIMP.

You can set the "shape" of the gradient with the Gradient pulldown menu on the gradient Tool Options. You can also set whether the gradient repeats or not, using the Repeat pulldown menu.

Once you have chosen a gradient to use, click and drag on your selection, or on the entire image, to apply your gradient. For most gradients (but not all), the length of the drag affects the range of the gradient; a short drag will equate to a compact gradient with more defined edges between colors, while a long drag will produce a wider gradient with less clearly defined edges.

Draw sharp pencil strokes

The pencil is used to draw lines, curves or shapes with sharp, defined edges. See the section called The Brush Selection Dialog for instructions on selecting brushes for use with the pencil.

Paint fuzzy brush strokes

The paintbrush is used to draw lines, curves, or shapes with soft edges. See the section called The Brush Selection Dialog for instructions on selecting brushes for use with the paintbrush.

Erase to foreground or transparency

Obviously, the eraser is used for erasing. See the section called The Brush Selection Dialog for brushes that can be used with the eraser.

Airbrush with variable pressure

The airbrush tool works much like an actual airbrush. You can control how much "paint" is "sprayed." High settings are darker and low settings are lighter and more uneven. See the section called The Brush Selection Dialog for instructions on selecting brushes.

Paint using patterns or image regions

The clone or stamp tool is used to select portions of the image, which are then used as "paint." The clone tool can be used to remove unwanted portions of an image, by painting over them with patterns from the image itself.

Click on the clone tool in the Toolbox to activate it. Then hold down the [Ctrl] key and click on the place in the image which will supply the pattern for painting. Release the [Ctrl] key. Click and drag to apply the selected pattern to the image. A + sign will follow along with the pencil icon of the clone tool. The + sign starts at the spot you picked and indicates where the "paint" is coming from in the image.

Blur or sharpen

The blur/sharpen tool is used to paint a blurring or sharpening effect on specific portions of an image.

Draw in ink

The ink pen is used to draw lines similar to those drawn using a pen; the line's thickness depends upon the speed of the drawing device (a pen tablet or your mouse). The pen's Tool Options include settings for the size and shape of the pen.

Dodge or Burn

The dodge/burn tool is used to adjust intensity values (the amount of white in each pixel) in an image.

The Tool Options for the dodge/burn tool allow you to set whether you want to dodge (increase the intensity) or burn (decrease the intensity). The Exposure slider sets how much you want to change the intensity, from 0 to 100%. The Mode sets which pixels will be affected: Highlights, pixels with high intensity values; Midtones, pixels with medium intensity values; or Shadows, pixels with low intensity values. The dodge/burn tool is used with a particular brush; see the section called The Brush Selection Dialog for more information about brushes.

Smudge

The smudge tool is used to blur or smear an image with the currently selected brush. See the section called The Brush Selection Dialog for more information on brushes.

Measure distances and angles

The measure tool can be used to measure a distance on an image, or to measure an angle from the horizontal. Double-click on the measure tool and select Use Info Window if you do not see the measurements window.

Colors

At the bottom of the Toolbox, you will see the active colors display:

Figure 9-2. The Active Colors

The active color square is depressed; you can see in Figure 9-2 that the black foreground color square is the active color.

By default, black is the active foreground color and white is the active background color. To "flip" the foreground and background colors, click on the .

Click on the active color box to display the Color Selection dialog:

Figure 9-3. The Color Selection Dialog

You can select a color "freehand." Choose one of the radio buttons for hue, saturation, value, red, green, or blue; pick a range of color from the middle bar; and then pick a specific color from the color square.

You can also just type in the correct RGB values or the hexadecimal value for the color you want to select.

As you choose colors by clicking on the color square, or by typing in exact values, you will see the active color box on the Toolbox change to the new color.

Color selection can provide you with some very complicated options. If you are interested in the GIMP's color capabilities, you should check out some of the more in-depth resources in the section called Additional Resources.

The Active Brush, Pattern, and Gradient

A square on the bottom right of the Toolbox displays the active brush, pattern, and gradient:

Figure 9-4. The Active Brush, Pattern, and Gradient

If you want to choose a different brush, pattern, or gradient, click on either the active brush, pattern, or gradient to display the palette of choices for each. Click on a choice from the palette to make it the active brush, pattern, or gradient.

The Brush Selection Dialog

When you use GIMP drawing tools, you can modify the attributes of the line you are drawing by selecting a particular brush.

Figure 9-5. The Brush Selection Dialog

To display the Brush Selection dialog, click on the active brush on the Toolbox. The Brush Selection dialog looks like Figure 9-5:

Click on a brush in the palette to select it. Click and hold the mouse button down to see more detail for certain brushes.

Selecting Areas in an Image

The GIMP provides six selection tools; they are the first six buttons in the toolbox. You can use these selection tools by clicking and dragging on the portion of the image you want to select. The GIMP also provides ways to modify your selection.

These modifications will only work while your selection is active. You can recognize an active selection by the moving dotted line around its perimeter (the marching ants).

  • When the mouse cursor is on your selection, the cursor becomes the move symbol. If you click and drag on the selection, you can move the selection.

  • The [Shift] key allows you to add to the selection. Once you have an active selection, if you hold down the [Shift] key and then use a selection tool to select a portion of the image, the new selection will be added to the active selection.

  • The [Ctrl] key allows you to subtract from an active selection. If you hold down the [Ctrl] key and then use a selection tool to select a portion of an active selection, that portion will be removed.

Loading a File

Before you can do any image manipulation, you need to somehow acquire an image. For example, you can scan an image, you can find one on the Internet (be careful about copyright restrictions!), or you can take a picture with a digital camera.

To load an existing file, click on File => Open. You will see the Load Image dialog, as shown in Figure 9-6.

Figure 9-6. The Load Image Dialog

The Load Image dialog displays your working directory — the directory you were in when you started GIMP. You can navigate up and down the filesystem tree by double-clicking on the Directories list on the left, then selecting a file to open from the Files list on the right.

Filename completion is supported by the GIMP. If you type the first letter (or more) of a filename into the Selection field and press the [Tab] key, the view will change to only those subdirectories and/or files beginning with that letter or letters.

The file you select will appear in the Selection field near the bottom of the dialog. A thumbnail preview will be displayed on the dialog; alternatively, you will see a Generate Preview button. If you want to see a thumbnail of the image, click on the Generate Preview button.

Once you have selected a file, click on the OK button to open it. You can also double-click on a filename to open it.

Saving a File

To save an image file, right click on the image and choose File => Save (or Save as). You will see the Save Image dialog if you choose Save as or if you choose Save but the file has not been saved before.

The Save Image dialog looks almost exactly like the Load Image dialog and navigation of the filesystem tree and choosing files works in the same way.

When you are saving an image, you will need to choose an image format. The GIMP supports a wide variety of image formats. In this chapter, we are going to talk about three of them: .gif, .jpg, and .xcf.

Image Formats

The vast majority of images on the Web are in one of two formats: .gif or .jpg. Both formats use compression to provide smaller file sizes and shorter download times (download speed is of paramount importance for everything on the Web). In most other ways, these two image formats are very different, and they are best used for different purposes.

The .jpg format is best used for photographs or images which use a lot of different colors.

The .gif format is best used for images which only use a few colors or which incorporate relatively large areas of the same color.

Before the GIMP will allow you to save an image as a .gif, you will need to convert to indexed color or to grayscale. Convert an image to indexed color by right-clicking on the image and then selecting Image => Mode => Indexed. The Indexed Color Conversion dialog will be displayed:

Figure 9-7. The Indexed Color Conversion Dialog

To minimize file size, a .gif image can only display a maximum of 256 colors. When you convert to indexed color, the RGB colors in the image are "standardized" to a particular palette of colors. If your image is going to be used on the Web, the safest palette choice is Use Custom Palette: Web. The palette optimized for the Web includes the group of 216 colors that are used by the majority of Web browsers.

After you have converted your image to indexed format, the GIMP will allow you to save it as a .gif file. Alternatively, if you try to save an unconverted file as a .gif file, you will be prompted to export the image to indexed color or to grayscale.

If you are working on an image in the GIMP, and you want to save it in order to work on it later, you should save it as an .xcf file. The .xcf format is the GIMP's native file format. If you create an image in the GIMP, or if you open an image and add GIMP effects (such as layers or masks) to it, you have added information to the image file. This information will be lost if you save the image as a .gif or .jpg. If you save a file as an .xcf file, you will preserve that information. When you re-open the .xcf file, you will be able to edit the file as if you had never closed it.

The Image Window

When you load an image or open a new image, the GIMP surrounds the image with a frame which includes helpful information and tools, as shown in Figure 9-8.

Figure 9-8. The Image Window

At the top, the image window displays a file identifier consisting of:

  • the name of the file (preceded by an * if the file has been modified),

  • the window number (sequential from 0 for the first image opened when you start the GIMP),

  • the view number (sequential from 0 for each image view),

  • the image type: RGB, Indexed, or Grayscale,

  • the amount of the image that can be seen in the window, depending on if you have zoomed in on the image.

At the top left, if you click on the icon, the image menu will appear.

To help you visualize the size of your image, the GIMP provides horizontal and vertical rulers. You can toggle these off and on by right-clicking on the image and selecting View => Toggle Rulers.

At the bottom left, you will see the position of the mouse cursor on the image, measured from 0,0 at the top left corner.

Just above the mouse cursor position window, you will see two square icons, which are used for creating quick masks. Basically, masks are selections which can be saved and used again. We will not cover masks in this elementary chapter, but if you use the GIMP for complex images, you will find masks to be very helpful. Please see some of the sources listed in the section called Additional Resources for more information on masks.

Near the bottom right, you will see an icon that looks like the move tool icon. This is called the panner. If you are zoomed in on an image, you can click on the panner to display a thumbnail of the whole image. Then you can click and drag on the thumbnail to pan the image view in your image window.

Along the bottom of the window, next to the mouse cursor position window, you will see two status fields and then a Cancel button. The first status field displays the file name, unless a plug-in is running (for example, if you are applying a filter or a Script-Fu to an image). If a plug-in is running, the name of the plug-in will appear in the first status window. The next field is empty, but will display a status bar for a running plug-in. Finally, the Cancel button allows you to stop a running plug-in.

Helpful Keyboard Shortcuts

Like many other applications, the GIMP makes it easy to accomplish tasks without taking your hands off the keyboard. Here is a selection of helpful keyboard shortcut commands:

Table 9-1. Keyboard Shortcut Commands

CommandKeystrokeCommandKeystroke
copy[Ctrl]-[c]select all[Ctrl]-[a]
cut[Ctrl]-[x]select none[Ctrl]-[Shift]-[a]
invert selection[Ctrl]-[i]undo[Ctrl]-[z]
paste[Ctrl]-[v]zoom in[=]
save file[Ctrl]-[s]zoom out[-]