Photo editing with the GIMP: Rounded corners Part III

Posted on

Edit Dec 6, 2009: I have also done a demonstration of one way to make only one, two, or three corners round, in “GIMP: Combining selections.”  In it, I used the method of Part I to make a rounded selection, and then I added the desired square corners to the selection.

What?  Another post on making corners round in the GIMP?  Yes, that’s right.  Making round corners is very important and deserves a thorough treatment.

I’m kidding.  This time, the aim is a simple demonstration of a tool that has many uses once you’ve mastered it: layer masks.  So you could call this Part III on rounded corners, or Part I on layer masks! (Here’s an entry in the GIMP manual on layer masks.) Quick summary at the end.

In Part I and Part II, I demonstrated a couple of the GIMP’s built-in ways to make corners round: deleting everything outside a selection that’s the shape of a rectangle with rounded corners; and running the “Round Corners” filter, which does that and a bit more automatically.  These are both so quick and easy that if rounded corners were really my aim, say for graphics for my web page, I wouldn’t be looking for anything else.

When I first started using the GIMP, it wasn’t obvious to me what the point of a layer mask was or how to manipulate one.  But once I’d made the effort to become familiar with them, I was relieved to find that they were actually not that mysterious, or complicated, after all.

I got a bit tired of staring at my little Gatekeeper butterfly though (not the butterfly’s fault: I just looked at it for too long), so I’m going to use flowers this time.

Say we have a picture like this:

Dicentra spectabilis 'Alba,' I think.

It’s called Dicentra spectabilis ‘Alba’ (bleeding heart), according to the BBC Gardening website.

I didn’t plant it, and it’s no thanks to me that it’s still alive.  That goes for everything in our garden.

OK, now pretend we want to put round corners on this using a layer mask.  We’ll have to know what a layer mask is and does first…

The layer mask is a greyscale image you can make and apply to any layer in your image file.  As its name suggests, it masks the layer: it changes which parts of the layer can be seen, and which parts are invisible.

The principle is this:

Where the layer mask is white, your layer is visible.

In any region where the mask is black, the pixels of the image layer become transparent, and you can see through it to the layer below.

Any level of grey in between corresponds to a level of partial transparency.

It’s pretty easy to imagine doing all sorts of complicated things with this, but for now I’m sticking to my rounded corners.

As soon as you remove or disable the layer mask, you can see the whole image again.  This is one of the beautiful things about layer masks: they’re non-destructive.  This means it’s easy to try a lot of variations without having to make too many memory-consuming copies of your target layer or rely heavily on multiple “undo” levels.

Now to business.  As in Part I, I’m going to select a rounded rectangle to begin with (right-click on image; Select -> Rounded Rectangle).  I choose “radius” 20% (remembering this is actually the diameter of the curve it will make).  Now I have a selection in the shape of the image I want to end up with, like I did in Part I.

shot27Where I take a left turn relative to that, though, is that I now go to Select -> Save to Channel.

What that does is save the selection into a greyscale image in a place that’s easy for me to get at when I want to make it into a layer mask.  In this channel, whatever was inside the selection will be white (visible), and whatever was outside will be black (masked out).  If your selection was feathered, there would be a smooth transition from white to black, i.e. the mask you’ll eventually make would grade the image smoothly from visible to transparent at the edges.

shot28

Now if I go look in the Channels tab, I see a new channel called Selection Mask copy. Incidentally, if the Channels dialog is not showing, you can bring it up by doing: right-click; Windows -> Dockable Dialogs -> Channels. Any dialog you want to see can be brought up in a similar way.

The channel name is easy to change if you think you may want to have more than one and want to keep them straight: right-click on it in the Channels dialog and choose Edit Channel Attributes and give it whatever name you want. Renaming a normal layer works like this, too.

shot29
shot30

At this point, you may (like me) be wondering what “Fill opacity” refers to in the Channel Attributes dialog. That parameter has to do with how the channel looks if you make it visible over the image layer by clicking over to the left of it (in line with where all the eye icons are next to the Red, Green, and Blue channels).

I’ll demonstrate that in a sec, but first let’s click on the box at the right of the Channel Attributes dialog, the one that’s filled in black in the upper-left half.

shot31

This brings up the colour editor.   I’ve clicked at the top right corner of the colour box to select the colour red.

(Aside: Kindly notice that this dialog is called “Edit Channel Colour.” That’s because I have asked my Mandriva Linux system to use Canadian English. Nice, eh?)

shot32

This is what the Channel Attributes dialog looks like now. If I were to slide the “Fill opacity” slider to the right or left, the red in the lower-right corner of the box would get more or less opaque.

shot33

Now if we click to the left of the Selection Mask copy channel in the Channels dialog, an eye icon appears, indicating that the channel is visible….

shot34
…and the black regions in the channel show over our image as 50% transparent red. The red helps make it more visible than if I’d left it black, and the transparency lets you see what the mask will cover in the image.

You can leave the “eye” there and have the red corners showing, or click on it again and make the channel invisible. I’ll make it invisible at this point.

We still don’t have a layer mask, do we? That’s because I digress a lot.

Just one more thing before we get to the point. Prepare a white background layer: go into layers dialog and add a new one, fill it with white, and drag it so it’s underneath the image layer (like in Part I). You wouldn’t do this step if you wanted the corners to stay transparent instead of white.

shot36
Then, finally, make the layer mask: right-click next to the image layer, and choose Add Layer Mask (this is also available in the main menu accessed by right-clicking anywhere in the active image: Layer -> Mask -> Add Layer Mask).

shot35
This brings up a dialog that gives us the option (among other possibilities) to populate the layer mask with a channel. So select the channel we made before and click Add.

shot37

The layers dialog now looks like this.

Next to the little cartoon of the image, there’s now a little cartoon of the contents of the layer mask.  You can right-click on this and check or uncheck “Show Layer Mask” to toggle the main image window between the image and the mask, or “Disable Layer Mask,” which removes its effect without destroying the layer mask. Left-clicking on it, which is the same as “Edit Layer Mask,” makes it the thing you’re actively editing with any tools you apply (whether you’ve made it visible or not), so you have to remember to left-click on the image icon (or uncheck “Edit Layer Mask”) to edit the normal layer again.

And the image now looks like this:

beep2009-00-round

Boom, we’re done. Well, almost. Once you’re sure you’re happy with the masking you can right-click on the layer in the Layers dialog and choose Apply Layer Mask (or do Layer -> Mask -> Apply Layer Mask). Before saving as JPEG, I did Image -> Flatten Image. I tried saving as PNG, without the white background layer, and GIMP gave me the option to flatten or to merge visible layers before exporting. I chose to merge the visible layers, and the resulting file has nice properly transparent corners.

To sum up:

1. Make a selection in the desired shape (here, rounded rectangle).

2. Choose Select -> Save to Channel

3. (Optional) Make a white background layer and drag it below the image layer

4. Choose Layer -> Mask -> Add Layer Mask; “initialize” it to the channel with your prepared mask in it.

5. Choose Layer -> Mask -> Apply Layer Mask

6. Image -> Flatten Image or Image -> Merge Visible Layers

7. Save with a different filename (don’t overwrite your original photo file).

This was about the simplest layer mask you’ll ever see, and there are many ways to generate layer masks — including painting with the painting tools.  The possibilities are endless.

I think I’m finished with rounded corners for now.  Can’t guarantee about the layer masks.

Photo editing with the GIMP: Rounded corners Part II

Posted on

Edit Dec 6, 2009: I have also done a demonstration of one way to make only one, two, or three corners round, in “GIMP: Combining selections.”  In it, I used the method of Part I to make a rounded selection, and then I added the desired square corners to the selection.

Before I get into the promised more-complicated-but-more-powerful way to make corners round on a photo using the GIMP, I should quickly demonstrate the really-least-complicated way.  It’s so simple, actually, that perhaps this is the post to read instead of Part I.

Under Filters -> Decor, in my version of the GIMP (2.6), there’s an option called Round Corners.  This option will be greyed out (unavailable) if your image already has an “alpha channel” (a channel containing transparency information).  If your image has an alpha channel and you still want to use this filter, you’ll want to remove it.

shot22

You just choose your parameters:

shot23

Whenever it’s an option, I like to make modifications to a copy, rather than the image I’m happy with thus far, so I keep “Work on copy” checked.  Here is the result of the parameters above on a 500×500 image:

shot24

The “radius” parameter in the Round Corners script is actually the radius, in pixels, of the curve used to round the corners, unlike the “radius” in the Rounded Rectangle selection script I talked about in Part I, which is the diameter of that curve, as a percentage of one side of the image.  Since I have a square image 500 pixels on a side, if I choose here 250 pixels as the radius I should get a circle. I may as well demonstrate that here, along with the fact that “Add background” gives you white corners instead of transparent ones:

shot25

Here’s my circle, on a white background:

shot26

The white is in its own layer below the image, so when you save you’ll most likely want/need to flatten the image or let the GIMP’s export function do it for you.  If you check the “Add drop-shadow” checkbox, the drop shadow will go on its own layer too.

Just for fun, let’s add the default drop shadow to the 80-pixel-radius corners:

roundbutterflywithshadow

As is evident by now, this method is quicker and more versatile than the way I wrote about in Part I.  I still have my more complicated but sneakily powerful method to get a demonstration written about.

If my explanation doesn’t work for you, here’s the official documentation at Gimp.org:

Decor filters -> Round Corners (this is a lot more helpful than the entry on selecting a rounded rectangle)

GIMP Manual

In addition, I see there are actually quite a few rounded-corners tutorials already on the web so if you don’t like mine, a search for “gimp round corners” will get you lots of other options.

Photo editing with the GIMP: Rounded corners Part I

Posted on

roundedsquarebutterfly

Edit: This is not the first way I should have described, because it’s not the easiest way.  See Part II for the really, really easy way.  See Part III for using layer masks to do the same thing, but only if you’re interested in learning about layer masks, because rounded corners are incredibly fast and easy in the GIMP using the Round Corners filter.

Edit again, Dec 6 2009: I have also done a demonstration of one way to make only one, two, or three corners round, in “GIMP: Combining selections.”  In it, I used this method to make a rounded selection, and then I added the desired square corners to the selection.

If I insist that the GIMP is a good tool for manipulating digital photos, I should show it doing something, shouldn’t I?  Since I was recently interested in trying this, let’s do rounded corners. You may want to do this for effect on a photo, or maybe you’d like to make some round-edged web graphics.  There’s more than one way to accomplish the same effect, as is so often the case.  I’ll look at one method (“Rounded Rectangle”) with a couple of variations here, first in a long-winded fashion and then at the end, in point form.

Here’s a picture from my little butterfly-photographing spree this past summer.  I’ll go through how to make corners round on that.

squarebutterfly

As I learned back then, this butterfly is called a Gatekeeper.  It’s a little blurry.  Decided to flap its wings just as I wanted to take a picture.  Let’s not worry too much about that.  It won’t affect the corners, right?  Actually I kind of like the effect.

Here’s a screenshot of the image open in the GIMP.  I’m using it under Linux with KDE 4, but it runs under Windows and OSX, too.  It’s free.  I have my toolbox and tabs with settings and stuff over on the right, and the image gets its own window.  The layout is pretty configurable.  Everything that has a tab can have its own window, for example, so you can see it all at once (if you have the screen real estate).

shot01

Here’s a good place to demonstrate the right-click menu in the GIMP.  You can set your preferences so that there’s a menu bar along the top of the image window, but all the same options can be found by right-clicking anywhere on the image.  This brings up the main menu, and has the advantage that I don’t have to move my mouse up to the top of the window before clicking.  Just click with the right button wherever you are (as long as it’s on top of the image somewhere) and slide down to the menu item you want.  I find this a more natural movement and faster than using a menubar.

I should get down to the corner-rounding, shouldn’t I?  OK.  While I’ve got the menu open, I’ll choose Select -> Rounded rectangle.

shot02

This window pops up, asking how sharp the corners should be:

shot03

I choose 20%, and here’s what it gives me.  There are now round corners delineated by dotted lines (“marching ants”):

shot04

From what I can tell, “radius” and “percent” in the Rounded Rectangle dialog box actually mean “diameter of the circle segment used to make the corner” and “percentage of the length of the shorter side of the photo.” So if you have a square photo and set the “radius” to 100%, this makes the selection the biggest circle that will fit inside your image.  So 20% means that if you visualize a whole circle starting in the round corner, that circle is 1/5 the height of the photo.

The situation at this point is that we have an area of the photo selected that has corners shaved off of it.

You need to decide whether you want the corners to be transparent or not.  If you are saving as a jpeg without transparency, then you may want them to be white (or another colour) to blend in with a background.

If transparent, I think the easiest thing to do is hit Ctrl-C to copy that selection, and then Ctrl-Shift-V to paste it as a new image (or with the mouse, right-click anywhere on the image and select Edit -> Copy, then Edit -> Paste as -> New Image).  Then you get this:

shot05

At the corners you see a checkerboard pattern: that’s like the table the photo is sitting on. You can see it through the transparent pixels in the corners. Save your image in a format that preserves transparency, and you’re done.

If you want opaque corners, there are two easy ways I can think of.  Let’s assume you want them to be white.

Way one: Paint in the corners. With the ants still marching around the rounded corners, right-click on the image to get the menu out, and choose Select->Invert, which makes everything that was selected unselected, and vice versa.  So now just the corners are selected.  Use the bucket tool to fill all the corners with the colour you want.  Ta-daa!  Done.

Way two: Put a white layer below the photo. Take the image above, with the transparent corners, and add a layer to it, filled with white.  There’s a button to create a new layer at the bottom left of the layers tab (at the very bottom of the “Toolbox” window, in my case):

shot06c

A window pops up asking for some details about the new layer I want to create.  You can give your layers names.  I’ll call this one “White background.” I’ve got the radio button ticked for a layer pre-filled with white.  By default it’ll make the layer the same size as the photo layer.

shot07

The new layer will appear above the one that was there before.  I only want to see white where my photo layer is transparent (i.e. the corners) so I click on the White background layer in the Layers tab and pull it down so it’s at the bottom of the stack as below.  (Yes, the stack of two layers.  I couldn’t think of a less grandiose word.)

shot08c

The photo window now looks like this:

shot09

Done.  Save in any format you need.  If your format doesn’t support multiple layers, the GIMP will ask if you want to “export” the file as a flattened image, which is what you want to do.  And if you put the picture into a blog post:

roundedsquarebutterfly

Ta-daa.  A roundy-cornered photo.

To sum up:

1. Open your image

2. Choose Select -> Rounded rectangle.

3. Choose how sharp the corners should be.

Now, if you want transparent corners:

4. Hit Ctrl-C to copy that selection, and then Ctrl-Shift-V to paste it as a new image.

5. Save in a format that supports transparent pixels.  Done.

Or, if you want white corners, either:

4. Choose Select -> Invert so the corners are selected.

5. Fill in the corners with white using the paint bucket tool.

6. Save.  Done.

or (white corners method 2):

4. Hit Ctrl-C to copy that selection, and then Ctrl-Shift-V to paste it as a new image.

5. Create a new layer filled with white.

6. Put that layer below the photo layer.

7. Save (or export).  Done.

Believe it or not, I’m not done writing about round corners yet.  I’ll write another post on a different approach to rounding the corners that adds a layer of complexity, but also adds flexibility to expand your ambitions far, far beyond simply shaving off corners.

Update Nov 6: Here’s what the official documentation at Gimp.org says about this method of rounding corners:

Select -> Rounded Rectangle

…well, a lot of parts of the GIMP Manual are more detailed than that.  It’s worth checking out when you want to understand a feature.

“Select -> Rounded Rectangle