Using Layer Masks in GIMP
Sometimes the perfect shot is not possible "in camera" and the only way to achieve the desired result is to create a single image from several raw shots. There are several ways to achieve this, but the best way - in that it does not directly overwrite any detail, allowing you to alter the mix easily in the future - is a technique called Layer Masking. This facility is available in both Adobe Photoshop and GIMP.
A common example where layer masks are often used is if the difference between highlight and shadow is extreme. In these cases the best way is often to create multiple shots at different exposure levels (-known as exposure bracketing) - so that each part of the picture has the correct lighting. Each separate image is then loaded into GIMP as a different Layer - and a Layer Mask created between each of them to blend the layers together into a whole.
Note: this is quite an advanced technique to pull off convincingly, so you may want to checkout various digital photography sites on the web for tips
In this section, we will aim to blend together two versions of the same photo with two different exposures: one exposed to the sky and the other for the rest of the image.
For this example, we'll assume that we only took once shot at the time - and only later realised the problem. Assuming we didn't have any clipping in the original, we can normally use UFRaw to adjust the exposure for first the sky, then the background, saving off the two versions as different files:

In GIMP (-and, indeed, also in Adobe Photoshop) top layers obscure lower layers by default. As a result, we will load the "sky" as the lower level, then the "foreground" as the higher layer. This will initially mean we cannot see the lower layer but we will then use the Layer Mask to reveal just the sky of the layer underneath.
Having created our two images in UFRaw, we load in the file for the sky ("Background" layer) and the file for the foreground ("Foreground" layer) as different layers in GIMP. The image below shows the two layers in GIMP:

Right click on the foreground layer and choose the "Add Layer Mask.." option:

Make sure the "White (full opacity)" option is checked, then click "OK":

You should now see a white rectangle to the right of the foreground layer thumbnail in the "Layers Palette" window. Next comes the tricky part! You need to use the selection tools to select the area of the sky in the main window: you can use the various tools in combination -in fact, that's normally the only way to achieve it! In this case, however, the sky was so washed out compared to the rest of the shot that a Threshold value of 20 and few clicks with the Select by Color Tool were enough to select the entire sky area (-shown surrounded by a dashed line below):

If the border between the selected/non-selected area looks too harsh, you can choose to blur the select edge by selecting the Feather function:
Select → Feather
Note: the higher the feather, the wider (and fuzzier) the edge will be

With the sky area selected, move to the layer mask by clicking on the white rectangle to the right of the foreground layer thumbnail. Next, select black from the colour swatch, click the bucket fill tool, then click anywhere inside the selected area. This will fill the selected area of the layer mask with black - making the mask transparent in this area (-in layer mask terms, white is opaque, black is transparent and other colours are somewhere inbetween):

You should now see the sky from the background layer showing through:

Hit the "Esc" key (-or press CTRL+A to select everything) to reveal the combined photo. As you can see, we now have a perfectly exposed sky and foreground - something that was not possible on the actual shoot:

We still have two layers though: we would advise saving this version as an .xcf file (-which preserves the layers) in case you need to tweak the image later, then using the Flatten Image option to reduce it to a single layer prior to printing:

The Flatten Image option will combine the two layers into a single ("Background") layer, which can then be saved in your favourite format (-e.g. .ppm, .gif, JPG, etc):
