Tuesday, July 29, 2008

Gimp Tutorial: Cutting an image from a solid color background.

This is something I've seen people ask about a lot, so I thought I would write up a tutorial on how to do it. The usual answer people give is to use the smart select tool, but there is a much better and easier way to get the desired result. So with that said, I present to you my first tutorial! Be sure to click the images for larger versions.

First you have to take your picture, I suggest starting with a high resolution snapshot since it makes working with finer details easier. You can find this option in Second Life under the Advanced (previously Client) menu. If you don't have this menu, hit Ctrl + Alt + D on a PC, or Opt + Ctrl + D on a Mac to show it and enable said feature. Now your snapshots will be much larger, just remember to turn this function off if you don't need it since the resulting screenshots also have a larger file size, which may be a concern for some of you.

picture

If you are taking a screenshot of an avatar, you should also turn off foot shadows, which can be done by pressing Ctrl + Shift + F5.

Now, open your image in The Gimp and select the part you need. Once you've done that, hit Ctrl + C to copy it, then go to Edit > Paste As > New image.

After you've done that, select the Color Picker Tool and click the solid color you wish to remove, it will now appear as the foreground color in the main Gimp window. Click that and you will see the HTML notation of the color you just selected. Highlight that notation and press CTRL + C to copy it, since we'll need it.


Totally didn't crop the image.

The next step is to go to Layer > Transparency > Color to Alpha. You will see a box pop up with "From: *Color Box Here* to alpha. Click that color box and color picker window will pop up with another HTML notation field. This is where we paste (Ctrl + P) the color value we just copied.



If all went well, your image should look like this:



If it is not transparent, be sure your image is not on the "background" layer, since for some reason The Gimp doesn't let you make that transparent. If that is the case, just duplicate the layer, delete the Background and try again.

You image should now completely lack the color you selected. What we want to do now is add that color back to the proper bits. To do this, create a new layer named "Solid", and do File > Fill with FG color, which should still be your selected color.

Place this new "Solid" layer under your alphaed picture, it should now look just like it did before we started!

Go back to your picture layer and right click the image, click Layer > Transparency > Alpha to Selection. This will fill your image with the "marching ants" selection effect. Press Ctrl + I to invert that selection and go back to the "Solid" layer.



Now things will start taking shape, with the inverted selection on the "Solid" layer, press Ctrl + X to cut it away from the image. You will now have a neat looking semi transparent layer under your picture. Duplicate the "Solid" layer and name the new layer "Transparent".


Great!

Next, go to the "Solid" layer again, right click the image and do > Layer > Transparency > Alpha to Selection, then Ctrl + I to invert the selection.

Now go to Select > Grow, type in "1" and hit ok. Doing this helps remove any background color leaking out from the sides of the final image as well as remove some weird artifacts that would otherwise show up when we change the alpha threshold.

The next step is to to go to Layer > Transparency > Threshold Alpha. Set the Threshold to zero and click ok.

Before:


After:


It's looking good, isn't it? We could use it just fine as it is, but we made that "Transparent" layer for two reasons. The first reason is that with the "solid" layer shrunk by one pixel, having another semi-transparent layer under the picture gives the edges a softer look.

The second reason is that it lets us preserve the transparency for things like hair or lace. Check the image below, do you see the solid color showing through on the hair? We are going to fix that!



Select the "Solid" layer and have the other two layers on top of it visible so you can better see what you're doing. Using the Free Select tool, zoom in and select the bits that should be transparent and cut them out with Ctrl + X as you go along.


That's much better!

Once you have cut away the bits that should be transparent from the "Solid" layer, merge all visible layers, save it as a .tga file and you're done!


Yay, done!

I hope this helps whoever may need it, good luck!

No comments: