Sunday, March 30, 2008

Created with the GiMP




Truth be told, the round banner was designed in Illustrator (GASP!).

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.

Geek Speak: more on file types

I was going to do another post on file types eventually, but it came up in the last Q&A post so I thought I'd do 800 words on some other considerations when it come to what file type to use when you save your files for web use.

The basic file types we have discussed are:

.xcf – this is the GiMP-native file type which, as we discussed before, can’t be read by your web browser, but preserves all the aspects of your file completely: resolution, layers, the works.

.jpg – this is the most common file format for photos because it doesn’t limit the colors you can use in an image, and it allows you to control file size by using compression. Compression, however, causes some image degradation (as we talked about last time), and .jpg also has another real liability which we will talk about today.

.png – this is an evolved form of .jpg, and it has other upsides as well, again, for today's post.

.gif – this format overcomes the "compression" problem for file size by simply limiting the number of colors you are going to use, and for many applications this is a very fine ideaer, but not so great for photos (as we saw last time). And it has a great application in web design.

Now, the real topic of today's post is "transparency" – that is, the ability to see something behind an image. So the first question to answer is: "Why should I care about transparency?"

Here are two images from my personal blog:





What I've done here is render the two images on a gray background with a red border so that you can see the "edges" of the images. They are both .gif files, but the first one is a normal rectangle that blows out to the actual edges of the file; the second has a lot of transparent space between the edge of the illustration and the edge of the file.

When you put them together, they look like this:



What I did there was to put the box in the background and the Firefox icon in the foreground – and the transparent parts of the icon let the background show through. Cool, yes?

This would be a reason to need and implement transparency in your web-ready images: to create layered effects.

This cannot be achieved with the .jpg file format: it does not support transparency. The good news, mostly, is that .png also supports transparency, but the bad news there are that some versions of Internet Explorer do not support .png. Some of you reading this blog may have found that out already as most of my images in my examples are .png. So for reliable web rendering of transparency, use .gif.

There are other issues related to this, but that's enough geek speak for one day. I'm sure many of you got lost someplace after "The basic file types we have discussed are ...", but someday you'll come back and find out you really did need to know this stuff.

Tuesday, March 25, 2008

GiMP or GiMPSHOP?

A reader e-mailed me and asked me about a port called "GiMPSHOP" -- why did I use "GiMP" rather than "GiMPSHOP"?

Well, two reasons:

[1] I had never seen "GiMPSHOP" before the e-mail

[2] GiMP doesn't need to look like photoshop to be just as powerful.

You can google "gimpshop" if you want to download it and try it out. I downloaded it for kicks and didn't see the appeal. Your milage may differ.

Comments are open for this post for your questions and comments; they are moderated, so if they don't show up right away, don't panic.

Sunday, March 16, 2008

Shadow-palooza and Layer Faire

Yes, welcome back. This last installment here has been written for about 2 weeks, but I've had a devil of a time getting the images embedded, so sorry 'bout that. I am sure many of you have come up with inventive solutions to the project we are working on by now. I am back on my Mac laptop today as I compose this lesson. Now, before we start talking about the process of creating a shadow of an object in a layer, let's talk about the dynamics of light and shadow in an image. This might seem like geek-speak when you look at it the first time, but look at two example images:



Now, what I've done is take an object which is casting a shadow in its original image, removed the shadow, and used the technique we are going to use to cast a shadow in our sandbox image to create two different shadows -- one like the original, and one which is frankly wrong.

Now, intuitively, you're going look at one of these objects and realize it looks, well, wrong. But how will you know which one is physically impossible? In the real world, we know that a shadow casts away from a light source -- like this:



Light comes from a source, strikes some object so we can see it, and behind the object -- away from the lightsource -- is the shadow. Duh, right? So which image of our examples has the shadow in the right place if this is so "duh"?

Look at the die a minute and see if it tells you anything about the light source. If you're really observant, you'll see a reflection of white light on the front-left edge of the die right here:



That reflection is a giveaway that SAMPLE #1 is a phony -- the shadow is resting under the light and not away from the light. If we look at the original image, we can see that its shadow is cast in the same direction as SAMPLE #2, under the die and away from the light source as indicated by the little reflection of light.



So what does that teach us? Well, it teaches us, in the very least, that we have to learn how to cast shadows by reading the light source in our lifted objects, and that our objects have to look like they are all under the same light bulb when they are all laid out together.

So here's our image right now:



And if we look at the knight closely, we can see the tell-tale shine of a direct light source right here:



So the lightsource is above the knight, and in front of it -- in the foreground, but outside of the picture itself, and maybe a little to one side. Some purist is going to say that the shadow should dip off to the right, but that's going to make our layout all messed up. So while I'm telling you that your shadow has to look realistic, I'm also telling you that as long as it's not a catastrophe, it'll be OK.

Now, we have one last conundrum to solve -- and that's how to get a shadow which looks somewhat like the knight in question. It's actually a very simple exercise in manipulating layers, and what I want you to do is go to your Layers dialog, select the "knight" layer, and click the "duplicate layer" button.

Your "Layers" dialog should now look like this:



Now, notice in that dialog the little "eye" icon to the left of each layer. It's sorta weird, right? Just to see what it does, line up on the eye for the "logo" layer and click it so the eye disappears. You'll notice that when the eye disappears, the layer is no longer visible in your sandbox, even though GiMP knows it's still there. Click the place where the eye ought to be to make both the eye and the layer re-appear.

Cool, yes?

OK -- now click the eye for the "knight copy" layer to make it disappear. It looks like nothing happened, but the layer is now invisible. We're going to work with the "knight" layer, so select it in the "Layers" dialog.

The reason we make the "copy" layer invisible is to keep us, the stupid human users, from getting confused. We're going to make a shadow out of this identical layer, but we don't want to accidentally start wrecking both "knight" layers in the process.

Now select the "knight" layer and in the sandbox image, go to the "Colors" menu. In that menu, select "Brightness/Contrast" (B/C)



You'll get a dialog that looks like the one below, and you're going to pull both sliders all the way to the left, as pictured below:



You'll see the results as a preview if you have the "preview" checkbox checked, but when you hit "OK", the sandbox image looks like this:



Pretty cool, right? The "Brightness" slider adjusts the color intensity of the image, and the "Contrast" slider adjusts the difference between colors. So moving them both to the left reduces the layer to a gray blob -- no distinct colors as all colors have been reduced to no brightness and no color.

Just as an enrichment exercise, think about how we were able to do what he have here: if the knight were not a dstinct layer, when we used the B/C sliders we would have decolorized the whole image. What we have instead is a single layer, independent of the rest of the image, which we have manipulated pretty significantly to make it into a shadow. Without keeping the parts of our image in separate layers, we would have never been able to do this.

We are, however, going to manipulate the color of this layer even more. If we wanted to make this later into "smoke", this gray stuff would be very serviceable. But we want a translucent shadow, and everybody knows that shadows are black.

In that case, we have to open the B/C dialog again, and this time run your sliders like this:



When you click "OK", your sandbox image will look like this:



And that's a nice black outline version of the knight. Now, if you make the "knight copy" layer visible, this black outline will disappear -- it will be hidden underneath the copy layer. And that's a bad thing right now, but go ahead and test it so you can see that we haven't lost the knight yet in this operation. Click the eye again to make the "copy" layer invisible again.

To keep our exercise as simple as possible, select the "knight" layer, grab the magic wand tool, drag the threshold up to 40, and select the black shadow outline. Your shadow image should have the "marching ants" around the outside of the shadow.

Next, go to the "Tools" dialog and select the "Perspective" tool. These are all tools we have used in other lessons, so I'm going to take it for granted that you can find the tools I'm talking about.

Take the perspective tool to the selected shadow and click in the middle of the shadow. You'll get something that looks like this:



That means you're ready to manipulate the shadow so that it looks like it's down flat on top of the logo, and you can also tilt it in such a way that it cuts from where the base of the knight will be over slightly to the left. You'll do that by pulling the corners until you get something that looks like this:



You'll have to hit "enter" to complete the edit, and then click the "anchor" button to put the adjusted shadow back into its layer, but you're practically a pro at GiMP by now -- or at least a competent basic user, anyway -- so that stuff is old hat.

After you have the shadow back in its layer, go to the "Filters" menu, and select "Blur", and in the nested menu select "Gaussian Blur". The link there is the geek-speak for those who want to read up on what a "gaussian" blur is vs. a normal "blur". The rest of us are just going top use the tool and love it.

When you select "Gaussian Blur", you're going to get this dialog window:



Use the scroll bars inside the dialog to get the preview image in the middle, and set the blur radius to "20". If you type "20" into the "Horizontal" field, and tab to the next field, the "Vertical" field will automatically fill in "20". and you can see the preview of the blur factor in the preview window.

Click "OK", and you'll have the basic image which looks like a shadow in a brightly-lit area.

To finish our work, we're going to make the "knight copy" layer visible so we can position the shadow so it seems to make sense relative to the solid object.

When you make the "knight copy" layer visible, you get something like this:



Before we go too far, grab the "Move" tool from the tool dialog, then select the "knight" layer -- the one which is actually the shadow. Then go to the sandbox image and drag it to the top and to the left of the imageso that little nip of shadow in the foreground at the edge of the base of the knight slides under the knight.

Use your best judgement, and make the shadow look as realistic as possible relative to the knight.



And that's not too bad -- except the shadow is too dark. It ought to show the logo through itself, and right now it doesn't do that very well. Go back to your "Layers" dialog, select the "knight" layer, and change the "Opacity" of that layer to 50 -- meaning it's 50% transparent.

And that's it. To save your image with layer, save it as a .xcf file; if you want to post it on the web someplace, use .jpg, .gif or .png.

Izzat cool or what?

Tuesday, March 4, 2008

Perspective and Layers

Yeah, shoot. there are three broken image links in this post, so forgive me as you read it. I will fix them later today -- I don't know what happened.


Well. Now that some of you have found this blog via my normal blog, we can get on with the festivities. Last time we thought about what it would take to remove an object in the foreground of some image so we could use it in another image like this:



And those who were with us last time are thinking, "hmph. Cent changed the logo on the 'flat surface' from last time." Yeah, well, I'm working on the PC at the bookstore tonight to try to give equal time to the win-heads, and I left one of my files at home rather than putting it on my flash drive, so I had to find another somewhat-suitable substitute for our work today.

But, because I'm that kind of guy, I'm going to upload all the files you will need right here, and you can download them yourself so you can work through the rest of this little exercise with me.

Here's the masked-off chess knight:



Here's the logo we'll be using for today's work:



And your first job is to open the GiMP, and create a sandbox image that's 500x500 pixels with a white background like this one:



Now, to build our target image, you need to flip the knight so that it's facing left instead of right. This should be easy enough if you've ever used Paint, and it's easy in the GiMP - you just have to know where to find the darned options. Look here:



And notice that GiMP is kind enough not to make you try to figure out if "Horizontal flip" means "flip on the H axis, meaning top-to-bottom" or "flip across the H axis, meaning left-to-right" - it gives you an icon so you know that if you want to flip left-to-right, you click that arrow. If you're easily-confused like me, this is a good feature. So flip the knight, and go back to your sandbox image.

Now, to make this whole exercise work, we are going to have to leverage layers pretty heavily, so stay with me. In the sandbox image:

go to your "Layers" dialog
click the "New Layer" button so you get the "New Layer" dialog
select the "transparent" radio button so the layer has completely empty
and name the layer "knight".


Before you click "OK", make sure the dialog box looks like this:



Now go back to the knight image, and use the magic wand trick we used there to select the image out of the black background:

set the wand to a threshold of "20"
select the black
invert the selection
shrink the selection by 2 pixels
feather the selection by 4 pixels
and copy.


Now breathe deeply. You're doing fine.

OK - we want to paste the knight into the sandbox image, so select the sandbox image and then do the following:

Select the "knight" layer
Paste the knight from the clipboard
Click the "anchor" button in the "Layers" dialog.


And when you're done, the sandbox image will look like this:



and your layers dialog will look like this:



Now, honestly, that's the hardest part of this exercise. The rest of this is ridiculously easy, and you're going to hate it that I had to teach it to you.

Use the "New Layer" button to add a new layer to the sandbox, and name that layer "logo". Make sure you make is a transparent layer. Now open the logo image I gave to you, above, and see if you can figure out, using the Magic Wand, how to select it so you can use it for our project.

Any ideas?

Yes, that's right:

Select the white part on the outside of the logo
Invert the selection
Expand your selection by 3 pixels (no need to feather)
And copy.


Then you move to the sandbox image and:

Select the "logo" layer
And Paste the logo.
(DO NOT anchor the image to the layer yet!)

Now, we have to make that logo look like it is printed on the flat surface under the knight, which poses two very interesting problems for us:

[1] how do we get the logo under the knight?
[2] how do we create the optical illusion that the logo is on a surface under the knight?

Let's solve these problems in reverse order. But to do this right, we need to see more of this object than we see right now, so select the floating selection in the Layers dialog, and make its transparency 66% so you can see the knight behind it. Cool, huh?

Now move the logo so its bottom lines up with the bottom of the knight, like so:



Now, we're going to use a new tool, surprisingly, called the "Perspective Tool", which looks like this:



And what you're going to do with it is click on the logo so you get something like this in your sandbox image:



Now, before we tinker with the perspective tool, let's talk about what putting an object into "perspective" means - this is Art School geek speak, so get a glass of water or something and think about this - because I'm trying not to geek you too often or too hard, but this is really, really important.

Look at this image:



As the chess board in this image extends away from the camera, the furthest border of the board looks like it's actually narrower than the closest edge of the board - the board looks like it tapers in! But what is actually happening here is what happens any time we look at something: things farther away look smaller, and all parallel lines running toward the horizon appear to meet in what is called the "vanishing point".

This applies to us in this exercise in this way: we have to make the logo look like it's lying flat on a surface parallel to the bottom of the knight so that its perspective matches the perspective of the base of the chess piece.

And that, unfortunately, requires some art rather than science. You manipulate the perspective box by clicking and dragging the corners. Here's what I did to the corners of the logo to make my logo look flat:



Notice that I have shortened the image in the same way the chess board up above looks like it's shorter than it is wide, and I have narrowed the top edge to make it look like it's farther away. Those who are really observant will notice that the pitch of the perspective on the right is not as steep as it is on the left - and that's because the logo doesn't sit dead-center under the knight. Once you have done the deed to your logo in your sandbox, hit "enter".

Now if you're a perfectionist, you could click the logo with the perspective tool again and tweek it out -- my opinion is that it is not yet perfect, but it's close enough for our exercise. The rest of us are going to adjust the transparency back to 100% and then click the anchor button so the logo sinks into the "logo" layer, thus:



And your "Layers" dialog looks like this:



Now, that's not right, is it? The logo has to go under the knight - which was out problem #1. Well, that's why we're using layers. Simply select the "logo" layer in the "Layers" dialog, and drag it so that it is stacked under the "knight" later - like this:



And your sandbox image looks like this:



And you can then drag the layers around so that they look like this:



Now, the last part is the really the ridiculously-simplest part - which is causing the knight to have a rightly-positioned shadow. But here's the thing: we have to use a new tool to do it, and I'm out of time today.

You try to figure it out, and I'll be by later this week to show you how I'd do it.

Saturday, March 1, 2008

The Magic Wand

OK: we have covered the really no-brainer tools in the tool set, but as we said, those tools aren't really all that better than the one you get with MS Paint. How do I go about building or designing really cool images like this one:



See: this image has 4 components -- the white background, the foreshortened logo which looks like it's laying flat on a surface, the shadow over the logo but under the knight, and the knight itself. And to make an image like this from other images, you have to be able to select areas of an image in ways a little more, um, artistic than merely using the rectangle-select tool.

That's where the magic wand (or, as the GiMP calls it, the "fuzzy select") tool comes in. But before we talk about the tool, let's all get the same base image to work with. The image below was downloaded from wikimedia.org, and falls under the wikimedia license for wikimedia images:



This is also the image I used to nab the knight for the image we looked at, above. But how did I peel it off the photo without, for example, picking up any of the grain of the chess board?

Well, let's open it in the GiMP and find out.



In that snapshot of my desktop (I'm using my Mac laptop), you can see that I have selected the wand tool, and I have the tool options open so we can sort of skip over the basics.

Now -- without changing any of the tool's setting, click someplace on the cheekbone of the knight's head. You should get something like this:



That's sorta weird, huh? You got a lot of area that's surrounded by the "marching ants", but not all of of the picture was selected. What the magic wand does is select an area of all the pixels in an image which meet the following criteria:

[1] they all touch each other
[2] they all fall inside the same color threshold as the first pixel you selected

Now, what does that mean? Take a look at your tool options for a second and notice that there's a slider there marked "Threshold". That slider (and the numbers next to it) indicate a degree of difference between the base pixel you select from and the most-different pixel color the tool will select. If you slide the slider all the way to the right, you will find that the highest value for the tool -- the highest level of threshold -- is "255", which is really an uber-geek notation for "make no distinctions -- include everything". At the risk of boring you to death, they use that number and not a sliding percent of threshold because 255 equals the largest number you can represent in an 8-bit number. The irony, really, is that this value is not an integer, so it's not really an 8-but number, so they could have used percentage and not confused the track ball off of normal people, but (yawn) I can see that I am boring you with geek-speak.

Anyway, in simple image -- like the one we made on the first lesson -- the magic wand can be set at a certain threshold and simply select objects that are more or less a uniform color, and you can suck them right out of their context. But we have a problem with the chess piece: this image has a really consistent color pallet. That is: there are a lot of colors that are really close to each other in threshold. To see what I mean, set your threshold to "75" and select the horse's cheek again. You get something like this:



Now, that looks pretty good, right? Most of the knight is selected. The problem is that not all of it was selected -- look at the base, and under the chin, and where his eye would be, and in the crest of his mane -- these are dark areas which are as dark as the chess board which are outside the current threshold. But worse for us is on the left at the bottom of the piece where the threshold of the background is low enough that the places it touches the object we are trying to select cause the tools to select the background. If we raise the threshold any higher, we're going to get a lot of stuff we don't want, and we won't be any better off than we are right now.

See: it seems pretty obvious that we should try select the object in the foreground because it is a consistent color -- it should be the easiest to select because it is all nearly the same color. But it turns out that it's not consistent enough, so we're going to select the background instead, using a function of this tool called "add to the current selection".

Set the tool threshold to "20", which is pretty aggressive but not so much that we can't make fine distinctions in the image. Then go back to the image, and type SHIFT-CTRL-A, which will select none of the image. Now point your magic wand at some part of the black area of the image at the top and click it. You'll get something like this:



That makes a selection of all the darkest parts except that object that's in the background there that makes a light spot. To fix that -- that is, to add it to the selection -- hold down your SHIFT key and click the light-colored spot. It'll select the middle of the light area because the range of the colors in this area is greater than the threshold of our tool. If you do that a second time in the donut ring that's left, it will add that to the selection as well, like this:



Now, that seems really cool until we get to the hard parts in the chess board. Because when we SHIFT-select a spot below the black areas, we get something like this:



What that's really going to take is a little patience and some repeated application of the SHIFT-select technique as you find areas of high contrast that don't allow you to make quick work of it like we did at the top of the image.

One really valuable tip, however, is that if you SHIFT-select an area and it swallows up a wrong part of the image, you can type CTRL-Z (undo), and GiMP will undo the last selection so you can try again.

OK: SHIFT-select the parts of the image until you get something that looks like this:



Notice that even my image has some salt-and-pepper spots in the grain of the board that aren't fully selected. We will clear that up in a second. First, go back to your tool pallet and reset the FB/BG colors, and swap the black to the background. We're going to do this so that we create an image with a very high contrast between the object we want to capture and the rest of the image.

Now take a deep breath, and type CTRL-X to cut out everything you have selected so far. Your image should look like this when you're done:



It's not a perfect image (yet), but this will be much easier to work with than what you had a minute ago. Reset your FG/BG colors so black is in the FG, and select your paintbrush. Then, at the bottom of your image there, you see a drop-down menu with "100%" selected. Drop it down, and select "400%" so you can really see what you're doing, and paint over the flecks of chess board that are left in your image. When you're done, the image will look like this:



Now, that looks like you're pretty much done, but you're not -- because now you have you get this object out of that black field and into another file, and that's not as simple as it sounds. Many people will simply use the wand to select to black field, go up tot he "Select" menu, choose "invert", and copy the object out from here. If you do that, here's what you get:



Notice that this image has a really phony-looking dark border around it, and the one in our original example doesn't. How does one fix that? Well, go back to the "Select" menu, and look at your choices a second.



First, make sure you have chosen "invert" to select the knight and not the black background. Second, select "Shrink...", and in the dialog box that opens, shrink your selection 2 pixels. Third, we're going to soften the edges of your selection by using the "Feather..." option. "Feathering" a selection means that the GiMP is going to take the edges of what you have selected and make the ones at the other-most edge partially transparent, inside the depth of pixels you choose.

When you choose "Feather..." in this exercise, type "4" for the number of pixels to feather. If you then copy the image out of your original and paste it into a new file, you'll get something like this:



See: now you have a tool which is worth the price of admission. Find another image you want to pull out of its original context and try to do it yourself, and we'll come back to this another time.