Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Tutorial: Making a transparency mask using GIMP

Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
06-09-2007 13:27
In several other threads here I've seen folks ask how to make a transparency mask (alpha channel) using GIMP, and the answers are one or two sentence responses that are misleading and produce inferior results in most cases.

Here's how I make an alpha channel in GIMP, starting with a relatively arbitrary image. Ideally the background is the opposite of the item (i.e., light colored item on black background, or dark item on white background), but often it's not quite the case. My method handles all cases, but of course you have the most trouble when the background is a similar shade to the item.

Open the picture in GIMP. I assume we're starting with a jpg or gif, so there's no alpha channel to begin with. Later I'll cover the case where there is an alpha channel and you want to touch it up or fix a problem you didn't notice when you created it earlier.

I'm using GIMP without the stuff that makes it try to look like Photoshop.

1) Menu "Layer -> Mask -> Add Layer Mask ...". A popup appears; select "Grayscale copy of layer". If the background is light, also select "Invert Mask". Hit OK.

2) Menu "Layer -> Mask -> Show Layer Mask" (put a check mark there). Now you're looking at the transparency mask -- what will eventually become the alpha channel.

3) "Layer -> Colors -> Threshold". Drag the slider until you get the best results where there are few or no speckles in the black background, and the foreground is mostly white. Black will be transparent, white will be opaque (your image). In difficult cases you may find you want to skip this step -- use your judgement.

4) In "The GIMP" panel, double click the foreground and background colors to make them black and white. (It doesn't matter which is which, because you'll be switching them.)

5) Use the pencil and paintbrush tools (with appropriate brush shapes -- I use circles of different sizes plus a few bigger circles I added) to make what's clearly background black and what's clearly foreground white. Skip any areas where you're not completely sure whether it should be transparent.

Note that if you click one of these tools and then shift-click another spot, it's like dragging the tool in a straight line from the first spot to the second. This is a real time saver.

Also note the little arrow thing by the foreground/background colors in "The GIMP" panel -- that swaps foreground and background colors. There's also some shift-like-key to do this temporarily, but I never seem to find it.

6) When you have the bulk of it done and now need to actually see the item to touch up, use "Layer -> Mask -> Show Layer Mask" again (unchecks it). Now you can see your image, with the gray checked background showing wherever the image is transparent.

7) Continue using paint and pencil tools, zoom in and out (shift-mousewheel), and handle the fussy parts. Remember that painting black makes it transparent and white makes it opaque.

I find that gray on the edges is often helpful in making an image work better in SL. This is particularly true for images that seem to have lines at the edges that aren't the background color but aren't really the item -- they're "inbetween" colors caused by JPG compression earlier in the process, or other reasons. If I try to just make them invisible, I find I get odd jagged edges. Instead I use the edge of the paintbush tool (which blends as it paints) or sometimes paint a gray shade here or there to help these lines fade out but not completely disappear.

When you're happy with the results, we're ready to flatten, resize, and export as TGA.

8) "Layer -> Mask -> Apply Layer Mask". After you do this you won't see any difference. This bakes the transparency mask into the alpha channel. Why it doesn't put it there in the first place I have no idea, but that's how it works in GIMP. No doubt they have a good reason.

Now, save the image GIMP project, in case you want to make adjustments later. Use "File -> Save As", and replace the original file extension with "xcf". If you forget that, just "Select by file type", and it's the top one.

9) Resize appropriately for SL. You may have been working on a full-resolution image, and if so you need to resize it to download quickly ingame, so your objects rez quickly. (Image size issues are covered quite thoroughly in a sticky post on this forum.) To resize, use "Image -> Scale Image". A "Scale Image" panel appears. I generally put 64, 128, or 256 in one of the boxes and let GIMP calculate the other box under "Image Size". Under "Quality", select Cubic -- no point in being sloppy here, it works plenty fast.

10) Save as TGA file: use "File -> Save As", and replace the extension with "tga". Bingo. Leave the origin as lower left, and I disable compression. (Compressing the image may speed uploading time, but won't affect anything other than that except reducing image quality somewhat.)

11) Upload the image and have fun!
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
06-09-2007 13:30
Here's how to modify the transparency mask in an image that already has one. It's easy.

Load the image, and then use "Layer -> Mask -> Add Layer Mask".

When the popup appears, select "Transfer Layer's Alpha Channel", and away you go. As above, you can use "Layer -> Mask -> Show Layer Mask" to select whether you see the mask itself or the object with the mask applied.
Jabath Steuart
Registered User
Join date: 4 Sep 2006
Posts: 17
07-20-2007 05:55
There are lots of answers about MAKING alpha channels in Gimp, what I want to know is how do you OPEN a 32-bit TGA (i.e. one with an existing alpha channel) with the alpha channel intact? Do i need a plugin?

Apologies if this is answered in one of the many tutorials, but I'm doing this for a friend not myself and don't have time to do any more searching (spent two hours on this already).
Chosen Few
Alpha Channel Slave
Join date: 16 Jan 2004
Posts: 7,496
07-20-2007 08:39
From: Jabath Steuart
There are lots of answers about MAKING alpha channels in Gimp, what I want to know is how do you OPEN a 32-bit TGA (i.e. one with an existing alpha channel) with the alpha channel intact? Do i need a plugin?

Apologies if this is answered in one of the many tutorials, but I'm doing this for a friend not myself and don't have time to do any more searching (spent two hours on this already).

What do you mean by "with the alpha channel intact"? What happens when you open a 32-bit TGA now? When you go to the Channels palette, do you not see all 4 channels listed?
_____________________
.

Land now available for rent in Indigo. Low rates. Quiet, low-lag mainland sim with good neighbors. IM me in-world if you're interested.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
07-20-2007 09:14
From: Jabath Steuart
There are lots of answers about MAKING alpha channels in Gimp, what I want to know is how do you OPEN a 32-bit TGA (i.e. one with an existing alpha channel) with the alpha channel intact? Do i need a plugin?

Apologies if this is answered in one of the many tutorials, but I'm doing this for a friend not myself and don't have time to do any more searching (spent two hours on this already).
You don't have to do anything special to get the alpha channel to load.

If you want to edit the alpha channel, just go to Layer -> Mask -> Add Layer Mask, and then select "Transfer Layer's Alpha Channel". Then use the same methods discussed above to edit the mask, and convert it back into alpha channel.
Sue Saintlouis
Registered User
Join date: 8 Dec 2006
Posts: 420
07-20-2007 12:53
Oh this is great!!! Thank you Learjeff :)!
Peggy Paperdoll
A Brat
Join date: 15 Apr 2006
Posts: 4,383
07-20-2007 16:27
I just gave it a shot on an old JPEG photo I've been eying for a texture........but afraid of the hours of cutting and erasing to get what I wanted. Whoaaaa whooo!!! It works!!!

Thank you Learjeff. :)

edited because Learjeff's name in NOT LearJET!!! LOL
Jabath Steuart
Registered User
Join date: 4 Sep 2006
Posts: 17
07-31-2007 11:01
Sorry, been to busy to follow this up. When I (and my friend who I'm trying to help) open a 32-bit tga in Gimp 2.2.17, there are no alpha channels, in Photoshop CS, there are.

This is the file in question:

http://slsailing.org/system/tako_3_sail_public.zip

I will try to verify with a different file when I have some time.

Thanks.
Anna Gulaev
Registered User
Join date: 25 Oct 2006
Posts: 154
07-31-2007 19:35
From: Jabath Steuart
Sorry, been to busy to follow this up. When I (and my friend who I'm trying to help) open a 32-bit tga in Gimp 2.2.17, there are no alpha channels, in Photoshop CS, there are.


I don't know why that is, but if you open it in PS and save it as a 32-bit TGA it will then open correctly in Gimp.
Jabath Steuart
Registered User
Join date: 4 Sep 2006
Posts: 17
08-01-2007 07:29
god, dont' know why i didn't try that. must be a problem with the file, will send the new one to the owner, thanks for that

:)