Chapter 7

Editing Photos on the Raspberry Pi with GIMP

IN THIS CHAPTER

check Installing GIMP

check Understanding the GIMP screen layout

check Resizing, cropping, rotating, and flipping your photos

check Adjusting the colors and fixing imperfections

check Converting images between different formats

We live in probably the best-documented era in our history. Not only do we write about our daily lives in blogs and on Facebook, but many people also carry cameras everywhere they go, built into their phones or other electronic devices. More serious photographers might have dedicated digital cameras. Whatever you use, and whatever you do with your day, photography is a great way to record your life and express yourself creatively.

The Raspberry Pi can play a part in this activity, enabling you to edit photos to improve their composition and quality. The photos generated by digital cameras are quite large files, however, so a Raspberry Pi with just 256MB of memory struggles to process them, and often becomes impractically slow or crashes when processing large images, in our experience. The 512MB edition of the Pi, which you own if you bought a Model B after October 15, 2012, delivers much better performance, although you still need to be patient at times. The performance on the Raspberry Pi 2 or 3 is greatly improved, and you should find that you can carry out image manipulations easily with them.

In this chapter, we introduce you to GIMP, one of the most popular image-editing packages, and we give you some tips for editing your photos with it. You learn how to resize, crop, rotate, and flip your photos. We also tell you how to change colors and fix any imperfections, such as dust or unwanted details, in your shots.

Some of the skills we describe here are valuable for working on other projects in this book, too. In particular, resizing images so that they’re smaller cuts the amount of memory they require and makes it easier to use them in other programs, including LibreOffice (see Chapter 6) and Scratch (see Chapter 9).

Working with GIMP

The program we use is the GNU Image Manipulation Program, known as GIMP for short. It’s a highly sophisticated tool, and it’s available for free download not just on Linux but on Windows and Mac computers as well.

To install GIMP on your Raspberry Pi, enter the following at the shell:

sudo apt-get install gimp

If you experience any difficulties, consult Chapter 5 for advice on installing software.

After installation is complete, you can start GIMP from the Graphics category on the Applications menu in the desktop environment. (See Chapter 4 for more on the Applications menu.)

Understanding the GIMP screen layout

Figure 7-1 shows the screen layout of GIMP. GIMP can be used in such a way that each pane of tools or content is a separate window onscreen — though we find it easier to arrange everything in a single window, especially when we’re using a smaller screen. If your layout looks different from the one shown in Figure 7-1, click to open the Windows menu at the top of the screen and select Single Window Mode.

image

©1995–2012 Spencer Kimball, Peter Mattis, and the GIMP Development Team

FIGURE 7-1: GIMP enables you to edit photos on your Raspberry Pi.

When GIMP opens, the large area in the middle is empty, with a picture of Wilber, the GIMP mascot, in the background. We’ve used the File menu in the top left to open a photo for editing, which you can see in the center pane.

Across the top of the screen is a bar with menus for File, Edit, Select, View, Image, Layer, Colours, Tools, Filters, Windows, and Help. You can browse these menus to get an idea of what the program can do, and to find options quickly if you don’t know which icons they use on the toolbar.

On the left is a pane that contains icons for the tools at the top and the tool options at the bottom. When you roll the cursor over a tool’s icon, a tooltip pops up to tell you what it does. When you click a tool to select it, the options at the bottom of the pane change, depending on the tool you’re using. For example, if you’re using the paintbrush, the options cover properties such as opacity and the brush type.

The pane on the right is also divided into halves. The top half has tabs for Layers, Channels, Paths, and History. Of these, the Layers and History tabs (refer to Figure 7-1) are most important for new users because they enable you to edit your photos safely.

The History tab enables you to retrace your steps if you make changes you don’t like.

Layers are used for adding new elements to an image without disturbing whatever is underneath. For example, if you want to add text to an image, you do that in a new layer on top of the old one. If you change your mind, you can just remove the layer, and the picture underneath is unchanged. The Text tool (which has an A as its icon) automatically adds text in a new layer when you use it. If you intend to use the drawing tools, add a layer for each part of the drawing by clicking the New Layer button under this pane (refer to Figure 7-1). New layers appear on top of older layers, but you can change the order of layers by dragging them up or down in the pane on the right. Those near the top of this pane appear nearer the foreground in the image. To hide a layer temporarily, click the Eye icon next to it in the pane.

The bottom half of the right pane is for brushes, patterns, and gradients. The brushes are used when you’re drawing or painting on the image. The patterns and gradients are used for the Fill tool, which fills in a part of the image with a particular color or pattern.

You can change the width of the left and right panes, as we have in Figure 7-1, to make it easier to see all the tabs. Put the mouse cursor at the edge of the pane adjoining the central image area. When the cursor turns into a two-headed arrow, click and drag left or right to resize the pane.

Resizing an image in GIMP

One of the most useful things you can do in GIMP is to resize an image. All computer images are made up of pixels, which are tiny colored dots. Sean’s camera produces images that are 4,272 pixels wide and 2,848 pixels high. High-quality images like these are great for printing photos, but if you just want to use pictures onscreen, quality comes at a price. That level of detail requires a large file size, and big files can significantly slow down your Raspberry Pi. Often, you can use a lower-quality image without noticeably affecting the end result, assuming that it will be displayed only on the screen.

Here’s how you can resize an image using GIMP:

  1. Click to open the Image menu at the top of the screen, and click Scale Image.

    A window like the one in Figure 7-2 opens.

  2. In the Width box, enter in pixels the width you want the final image to be. Press Enter when you’ve finished entering the width.

    If you want to put a holiday snap on your website, you probably wouldn’t want it to be more than 500 pixels wide. If you want to use a photo as a Scratch background (see Chapter 10), the ideal size is 480 by 360 pixels.

    When you enter a new value for the width and press Enter or Tab, the height is updated automatically, so the image stays in proportion and doesn’t become stretched. You can also enter a value for the height and have the width calculated automatically. If you want to be able to adjust the width and height independently, click the chain to the right of their boxes to break it.

  3. Alternatively, instead of using absolute values for the width and height, you can resize the image to a certain percentage. Click the Units drop-down list box (it says px) and choose Percent.

    The values in the Width and Height boxes will then be percentages. For example, you would enter 50% to shrink the image by half. The size of the image in pixels is shown under the Height box.

  4. When you’ve set the size, click the Scale button.
image

©1995–2012 Spencer Kimball, Peter Mattis, and the GIMP Development Team

FIGURE 7-2: The scale options in GIMP.

tip At the bottom of the screen, underneath the Image pane, you can see some information about the file, including the current zoom level, which is how much the image has been magnified or reduced for you to view it. If you set this to 100%, you can get an idea of how much detail is in the image now, and it’s easier to edit too.

warning Resizing an image reduces its quality. This would be noticeable if you tried to create a high-quality print of it later. Don’t overwrite an existing image with a resized version. Instead, save the resized image by choosing Save As from the File menu at the top of the screen and giving it a different filename.

Cropping your photo

If your photo has excessive space around an edge, or if you’d like to change the composition of the picture, you can cut off the sides, or crop it. To do that, follow these steps:

  1. Click the icon that looks like an art knife, or press Shift+C to choose the Crop tool.
  2. Click the image in the top left of the area you’d like to keep, hold down the mouse button, and drag the mouse down and to the right.

    When you release the mouse button, a box appears on the image, as you can see in Figure 7-3.

    The inside of the box shows which bits of the image will be kept. Anything outside the box is cut off when you crop the image. You don’t have to get the position or size of the box right first time, because it’s easy to adjust.

  3. Click one of the corners and drag the mouse to change the size and shape of the box. You can also click and drag along an edge inside the box to adjust the width or height.
  4. To reposition the box, click and drag in its center.
  5. To crop the image, click inside the box or press the Enter key.
image

©1995–2012 Spencer Kimball, Peter Mattis, and the GIMP Development Team

FIGURE 7-3: Cropping a photo in GIMP.

tip If you make a mistake, you can use Ctrl+Z to undo, or use the History pane (refer to Figure 7-1) to go back to a previous version of the image.

Rotating and flipping your photo

If you rotate your camera sideways to take a picture, you might need to rotate the resulting image too. The easiest way to do this is to click to open the Image menu and then use the Rotation options on the Transform submenu there. You can rotate clockwise or anticlockwise (counterclockwise) by 90 degrees, rotate the image by 180 degrees, and flip it horizontally or vertically.

tip For a simple rotation like this, it’s quicker to rotate a photo using the desktop’s Image Viewer. (See Chapter 4.)

If you have a photo that’s slightly wonky, you can manually adjust it in GIMP. Click the Rotate tool (or press Shift+R) and you can enter an angle for rotation, or click and drag the image to rotate it. To change the pivot point about which the picture rotates, click the circle in the middle of the image and drag it.

warning This Rotate tool (unlike the options in the Transform menu) only works on the currently selected layer. (You can select a layer by clicking it in the top pane on the right.) If you plan to make other modifications to your photo, we recommend you correct its rotation before you add other layers.

Adjusting the colors

In common with other image editing programs, GIMP has options for adjusting the colors in a photo. You can find all these options on the Colours menu at the top of the screen. If your picture has a tint of color you don’t want, or if you would like to add a tint, use the Colour Balance settings to alter the amount of cyan, magenta, and yellow in the image. The Brightness and Contrast settings can help to bring out detail in shadows, or to give the image more impact.

There are also options on this menu (farther down, under Auto) to automatically adjust the colors using six different methods. These can give strange and undesirable results, but you can always undo them with Ctrl+Z if you don’t like them. The Normalize option can be a quick fix for images that look wishy-washy, and the White Balance option can fix pictures that don’t already have strong black and white areas.

tip The Color options only affect the currently selected layer. If you have added layers to your image, click the Photo layer in the top pane on the right before adjusting the color.

Fixing imperfections

On Sean’s holiday to Australia, he found a beautiful unspoiled beach in Darwin. He took a picture of it: a lone tree in the foreground, the shimmering sea, and wisps of cloud in a light blue sky. When he got home, he noticed that some idiot had left a crushed beer can in the foreground.

Thankfully, in GIMP, you can use a handy tool called the Clone tool to make little details like this vanish. It enables you to use part of the image as a pattern that you spray over another part of the image. In Sean’s case, he can use a clean piece of beach as the pattern and spray it on top of the litter. Hey, presto! The rubbish vanishes.

Here’s how you use the Clone tool:

  1. Zoom in to the image using the menu underneath it, and then use the scroll bars at the side of the Image pane to position the image so that you have a clear view of the imperfection.
  2. Click the Clone tool, which looks like a rubber stamp, or press the C key.
  3. Move the cursor to an unspoiled part of the image you would like to use as the pattern, or clone source.

    This needs to be somewhere as plain as possible, more of a texture than a shape, with no obvious prominent details or lines. Sky, grass, or sand is perfect.

  4. Hold down the Ctrl key and click the mouse button.

    A Crosshair icon appears on your image at that spot.

  5. In the tool options, at the bottom of the left pane, you can see the brush that is being used. Click the shape (a circle, by default) if you want to change it.

    For the best results, use a brush with a fading edge rather than a solid edge. You can change the size of the brush in this pane, too, by clicking the Size box and typing your preferred value. The bigger the brush you use, the bigger the pattern.

  6. Move the cursor to the imperfection in the image, and click the mouse button.

    This copies an area the size of the brush from the clone source to the place where you clicked.

    If you’ve done it right, the imperfection should appear to vanish. If you see unwanted picture details included in the pattern, either reduce the size of the brush or move the clone source. Repeat this step until the imperfection is gone.

    remember You can hold down the mouse button as you move the mouse to clear larger areas, but be aware that the clone source also moves as you move the mouse. If you replace a large area, you're likely to stray into a distinctive part of the image with the clone source, which will break the effect.

  7. Adjust the magnification at the bottom of the Image pane to view the image at 100%.

    Check whether you can see any evidence of your handiwork. If so, you might need to try another clone source or brush size. Otherwise, you’ve succeeded!

Converting images between different formats

There are several different file formats that can be used for images, but not all programs can open all files. If you want to use a picture as a background in Scratch (see Chapter 10), for example, you need to use .jpg files, which usually deliver the best quality for photos, or .png or .gif files, which are optimal for illustrations.

The default format used by GIMP is .xcf, which stores additional information about your editing session along with the picture, but this format isn’t widely used in other programs.

You can use GIMP to save the picture in a more widely used format, or to convert a picture between different file formats. First, open the image from the File menu, and then select that menu’s Export As option. The Export As window looks a lot like the Save window, but here you can click Select File Type (By Extension) at the bottom and choose the file format you’d like to convert the image into.

warning The conversion is quite memory-intensive, so on an older Raspberry Pi you might need to resize (shrink) a digital photo before you convert it.

Finding Out More about GIMP

There’s much more you can do with GIMP, and you can find detailed documentation on its website. To access it, click Help at the top of the screen, and click User Manual to open a menu showing the different sections. When you select one, it opens in your browser. Alternatively, in any browser, go to http://docs.gimp.org/2.8/en.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.118.95