Friday, March 28, 2008

Real Transparency in GiMP

OK -- alert reader JohnP has asked, in one of the Q&A threads, how to get a clipped image into a truly-transparent file so that you can use it over and over for other projects rather than having to lift it out of the original environment every time -- and that's a great question.

So what we're going to do is start with an image to lift out of an environment like this one:



And for the record, that image was downloaded from WikiMedia, and has a Creative Commons license, so we aren't stealing anybody's work; you can right-click it to download it so you can work with me. Also for the record, I'm at home on my Mac Tower in OS X.

Now, open the base image in GiMP and under the "Image" menu, go to "Scale Image ...". You'll get a dialog that looks like this:



Now, the only reason to do that is to find out what the height and width of the base image is so we can create a file to receive out clipping with is plenty large enough so that none of the edges get clipped. In this image, you'll see that the width is 375 and the height is 356. To avoid any possible mistakes and to make sure we do not require android-like precision to get the clipped image back out once we put it in the new file, we're going to make the new file 400x400 pixels.

To do that, type "CTRL-N", and then "Create a New Image" dialog will open, thus:



Which is fine as far as it goes. Before you set the height and width values for the rest of our project, I want you to look at something. There's a little carat above the "Help" button which says "Advanced Options". Click that, and look at the dialog, which should now look something like this:



Lots of other controls there, but I want you to look at the drop-down menu called "Fill with:". Select the option "Transparency" from that menu, fill in your width and height to 400, and then click OK. You'll get a new image that looks like this:



It doesn't look like much, but notice the checkerboard pattern in the image. That pattern represents space which exists inside the edges of the file, but has NO COLOR VALUE, so it appears (in GiMP anyway) to be TRANSPARENT. In this image, go to your "Layers" dialog, click the "Create a New Layer" button, name it "CLIPPING", and click "OK".

This is a perfect file to receive the flower from the base image we started with. Depending on the real estate on your monitor, you might want to minimize the receiving file while we work on the base file to avoid confusing yourself.

Now go back to your base file, and select all the green parts using the technique we used back when we pulled the knight chess piece out of its original image in this lesson. It should look something like this when you're done:



Fair enough, right? One note which will be useful to you is that I did NOT feather the selection - this is the raw "fuzzy selection" of the flower. Copy the selection, minimize the base image and maximize the receiving image.

Paste the clipping into the receiving image, anchor it into the "CLIPPING" layer, and it should look like this:



Seriously now: that's it. Save the file as "flower.xcf" to retain all the layers and transparencies, and you are literally finished. To get the flower out of that image, all you have to do is select the "CLIPPING" layer, go to the "Select" menu, and select "All", then copy and paste into your new image.

Hope that helps.