GAP Apply Layer Mask To Animation
Posted 29 November 2007 - 11:22 PM
In part 2, we will apply a layer mask to our animation:
And arrive at this result:
Beginning Notes: Layermasking can be used to add complexity to your animations. This tutorial shows a very simple example of a static layermask being applied to an animation to achieve a particular result. Layermaks can also be animated to achieve even more complex animations. The result achieved here can be accomplished other ways also, so this is by no means a unique method.
It does help to have some familiarity with Gimp and GAP. I have tried to make the tutorial as new user friendly as possible. However, without some familiarity, you may not completely understand why certain steps are taken, or why a given result occurs when some method is applied.
Start by opening a new 300x300 image window by selecting:
File | New
from the main Gimp toolbar window (the one with all the tool icons)
After setting up the image dimensions in the New Image window as shown above, press OK.
Next, fill the image with a bluish green color. To follow along exactly with this tutorial, use color:
You can do this using the Bucket Fill tool, or by just dragging the color from the Foreground Color showing on the main Gimp toolbar window to the image window.
We need to save the image to a format that GAP can work with. That general format is filename_000001.xcf. I usually use background_000001.xcf (XCF is the native Gimp image format). Save it into a working folder of your choice. It is always best to make a separate working folder to keep all of your work files in one place. I am saving all of my work files into a folder named gap_layermasking_tutorial (you choose the name of the folder/directory you want to add your files to).
I'm going to make a 60 frame animation. There is nothing special about using 60 frames. When you are doing this on your own, you could experiment with using more or less frames. Usually more frames produces a smoother animation, but a larger final file size, while less frames has the advantage of a smaller final file size, but less smooth animation.
We need 60 base frames for our animation. We have one already which is background_000001.xcf. We need 59 more. So from our background_000001.xcf image window select:
Video | Duplicate Frames
As shown in the above image, leave From Frame and To Frame set to 1. You can't use any other value in those boxes since we only have one frame, our background_000001.xcf image. Set N times to 59. This is how many more duplicate frames we want to make for the animation. Then press OK.
You will now have 60 sequentially numbered xcf image files in your working folder.
Open another new 300x300 image just as was done above. Save it as parts.xcf in your working folder.
Set your foreground color to Black.
Select the Text tool:
The text tool icon (highlighted in red above) looks like an upper case letter T. In the Text tool Dialog window (usually a tabbed window at the bottom of the main Gimp toolbar window), the selected font is URW Bookman L Not-Rotated with a size of 40px. No need to be concerned about any of the other font settings for this tutorial.
Click somewhere inside the parts.xcf window and type the word "Text" (without the quotation marks) in the Gimp Text Editor window that opens:
Then click on Close.
You now have a new Layer added to your parts.xcf image with the word Text somewhere in it:
In order to work more easily with any object using GAP, it is best to center that object in it's image window. Here is a quick method to do that for the Text Layer:
Check your Layers dialog window (should also be a tabbed window at the bottom of your main Gimp toolbar window) to see if the Text Layer is selected. Since you just added it, by default it should be selected. If it is not, just click on the Text Layer in your Layers dialog window to make sure it is selected.
Then in your parts.xcf window select:
Edit | Cut
The Text Layer disappears. Don't worry, it's in a memory buffer.
Next add a New Transparent Layer to your image by either clicking on the New Layer button at the bottom of your Layers dialog window, or by selecting:
Layer | New Layer from your parts.xcf window.
Change the Layer Name from the default New Layer to Text in the window that opens and click on OK.
Edit | Paste
The Text Layer reappears and it's centered. It is just a floating selection at this point though, not anchored to any Layer. So select:
Layer | Anchor Layer (or just click on the little anchor icon at the bottom of the Layers dialog window)
The word text is now centered in the image, and the layer has been anchored to the transparent Text Layer that was added previously.
Next let's crop that layer so it just fits to the size of the typed word "Text". Do this by selecting:
Layer | Autocrop Layer
Now return to your background_000001.xcf image and select:
Video | Move Path
In the Move Path window that opens, first make sure Instant Apply is selected (letter A in the image above). For the Source Image/Layer (B) choose parts.xcf/Text by clicking on the drop down window tab if it is not already selected.
(Note that the Source Image/Layer have numbers after them as shown in the image. Those are numbers that Gimp uses to keep track of objects and are unique to each instance of Gimp, so your numbers may not be the same as the one's in the image above.)
Stepmode © needs to be selected as None. For Handle (D) select Center. For the X and Y position values (these represent the position to place the Source Image/Layer on the background_000001.xcf image), set X to be 360 and Y to be 150.
Explanation: The Source Image/Layer (which is the Text Layer selected as parts.xcf/Text in the image above) is placed at a value of 150 for Y to be at the horizontal center of the image. (I'm not going to explain this fact. If you understand Cartesian coordinates this hopefully will not be an issue for you.) I have set the X value to be 360 to move the Text Layer beyond the right side of the image. (Try setting X to say 200 and you will see it moved into view. For the purposes of this tutorial and animation, the text begins beyond the right border of the image and moves across the screen disappearing beyond the left border of the image.)
If you use the slider to move the Text Layer, it will only go up to the value of the right border of the background_000001.xcf window. In that case, you can use the little up/down arrows (highlighted in red above) to adjust the value higher. You can also just double-click in the little box where the number is and delete the number in there and type in 360 and then hit the Tab key.
With the Move Path window still open, next click on the Add Point button (F). This adds a second keyframe to the animation and sets the first keyframe with the original values we inserted for our Text Layer, which in this case was just setting it at position X:360 and Y:150. After clicking the Add Point Button, we will set the final position for our animation (G). Set the X value to -60 (minus 60) (G). This moves the Text Layer beyond the left side of the background_000001.xcf image.
Again, if you use the sliders to change the X value, it will stop at a value of 0. Use either the little up/down arrows to the right of the X value or just double-click in the box where the X value is and change it to -60 (again, that is minus 60). We have told GAP the starting and ending values of the Text Layer. The value of GAP is that it will calculate and position all of the in between positions for each frame of the animation for the Text Layer.
Since Undoing with GAP is not trivial, it is always best to Preview your animation prior to clicking the OK button. So click on the Anim Preview button (H):
In the window that opens, select Exact Object on frames as shown above and then click OK. A little multilayered image and a preview window will be created. Watch the preview to see if the animation goes as expected. If so, close the preview window and then delete the little multilayered image that gets created and select Don't Save from the window that opens.
If your animation goes the same as the first animation shown at the beginning of this tutorial, then click OK on your Move Path window and let GAP place the Text Layer into the appropriate position in each of the 60 frames to give the appearance of motion by the text.
Our first animation has been created. Let's save it to a GIF file:
Video | Frames to Image
Accept the default values here and click OK. A new multilayered image will be created. If you select:
Filters | Animation | Playback from the newly created multilayered image, you will see the animation. We need to try to optimize this file to reduce the final file size before saving it. Select:
Filters | Animation | Optimize (for GIF)
Another new multilayered (and optimized) image gets created. From this new image select:
File | Save As
In the window that opens, type in the name anim_unmasked.gif for the name to save the file and then click the Save button.
The Export File selector window then opens:
Make sure that you select Save as Animation as shown above then click the Export button.
In the next Save window that opens, you can just accept the values there and click on the OK button. Your GIF image has been saved.
Close out the anim_unmasked.gif image window as well as the other multilayered image window that was created from the Frames to Image dialog previously. When asked select Don't Save.
This ends part 1 of the tutorial.
Posted 29 November 2007 - 11:54 PM
Return to the parts.xcf image window. Add a New Transparent Layer by selecting:
Layer | New Layer (or by clicking on the New Layer button at the bottom of your Layers dialog window). In the window that opens, name this layer Mask:
Click on the Rectangular Select tool in the main Gimp toolbar window. Then make a rectangular selection in the parts.xcf window around the Text as shown below:
As shown above, the selection is slightly larger and completely includes the word "Text". Make sure that your Mask Layer is selected in your Layers dialog window. Fill that rectangular selection with color White. Then invert the selection by selecting:
Select | Invert
Fill that selection with color Black.
Then from the parts.xcf window select:
Select | None
This will result in a layer that appears to have a white bar surrounded by a black border.
This layer is going to be applied as a layermask to the animation.
Explanation: Remember that for layermasks, black areas are made transparent, and White areas are made opaque (visible) for the Layer they are being applied to. We are going to apply this layermask to the Text Layer of each frame of the animation.
This will limit the Text to only being visible when it is positioned in the region of the white square. All other sections of that layer will be rendered transparent by the layermask.
From the background_000001.xcf image select:
Video | Move Path
In the Move Path window, select Instant Apply (A). For the Source Image/Layer select parts.xcf/Mask from the drop-down window if it is not already selected. Again, the numbers after the parts.xcf and Mask in the image above are unique to each instance of Gimp, so your numbers may not be the same. For Stepmode © select None. Finally, it is always a good habit to preview the animation before clicking ok, so click on the Anim Preview button (D).
In the window that opens, select Exact Object on Frames and click OK. A little preview will open along with a little multilayered image. If you view the preview, it will just show the Mask layer with no movement. This is correct, since we are just adding the Mask layer to the animation temporarily so that we can use it as a layermask for the Text Layer in each frame of the animation. Once you preview this boring animation, close out the preview, close out the little multilayered image that was created and select Don't Save. Back to the Move Path window, select OK and let GAP add the Mask layer to each frame of the animation.
Then from the background_000001.xcf image select:
Video | Frames Modify
As shown above, a new window opens. Click on the Function button in the upper left hand part of the window:
As shown above, once you click on the Function button, a menu opens. Select Layer Mask and then in the next menu that opens, select Copy layermask from layer above.
Notice that beside the Function button is shown the function we want to apply, namely Copy layermask from layer above. Change the Layer Pattern from a 0 to a 1. We do this because we are going to apply this action to layerstack number 1.
Explanation: When GAP adds a new layer to frames of an animation/video using Move Path, it places the new layer at the top of the stack of layers (layerstack). That top layer is called layerstack 0 (zero). Each successive layer below it is named 1, 2, 3, and so on. So, the Text Layer that we had added previously, was at layerstack zero (since GAP by default adds new layers to the top of the layerstack unless told otherwise). But then we added the Mask layer using Move Path, so that made the Mask layer as zero in the layerstack and pushed the Text Layer down by one level to layerstack 1 (one) (which caused the background bluish-green layer to be pushed down to layer 2). We are copying the Mask layer as a layermask for the Textlayer. The Mask layer, at layerstack zero, is one layer above the Textlayer, thus we "Copy layermask from layer above".
Click OK on the window after making the appropriate settings.
We must now delete the Mask layer from the animation. We are not removing it from being a layermask for the Textlayer. The Frames Modify function above already added it as a layermask to the Text Layer for each frame of the animation/video. If we leave it as is, and play the animation, all that we will see is the white bar with black border. We must remove this layer to ultimately reveal the transformed animation that results from adding the layermask.
From the background_000001.xcf window select:
Video | Frames Layer Delete
We applied our Mask layer to all 60 frames, so From Frame is 1 and To Frame is 60. The Mask layer is at Layerstack 0. Click OK and the Mask layer is removed from all 60 frames.
Test the resulting animation by selecting:
Video | Playback from the background_000001.xcf window.
After viewing it close out that window.
Next, we want to Apply the Layermask to the Text Layer for each frame of the animation. Again, GAP automates this. From the background_000001.xcf image select:
Video | Frames Modify
The Frames Modify window opens. Click on the Function button. This opens a menu. Select Layer Mask, then Apply layermask as shown in the image above.
This switches the Function name to be carried out as Apply layermask as shown above. The Layer Pattern is zero this time.
Explanation: Layer Pattern is the layerstack position we are applying the function to. The Text Layer moved back up to layerstack position 0 (zero) when we removed the Mask layer from the animation frames.
We are applying this function to all frames of the animation, so our From Frame and To Frame can be left as they are. Click on OK to apply the layermask to the Text Layer for each frame of the animation/video.
If you look at your Layers dialog window for background_000001.xcf, you will see that the Text layer no longer has a layermask associated with it. That is what we expect since the layermask has been applied. If you were making a more complex animation, you might be adding another layermask to the Text Layer, or even an animated layermask, depending on the situation and complexity of your animation.
Let's convert the animation to a GIF format just as on part 1 of this tutorial.
From your background_000001.xcf window select:
Video | Frames to Image
Again, just accept the defaults and click OK.
A new multilayered image will be created. This multilayered image will have 60 layers - one layer for each frame of the animation. Optimize the animation by selecting:
Filters | Animation | Optimize (for GIF)
An optimized multilayered image is created. From that window, select:
File | Save As
In the Save window that opens, save as filename anim_masked.gif and click on the Save button.
As before, make sure you have selected Save as Animation from the Export File window then click the Export button.
In the next window that opens, accept the values there and click OK. Your animation has been saved.
Finally, I added some text and a frame, and added a timing delay to the animation:
So much more that can be done to make the animation even more interesting. Thank you for checking out this tutorial.
Posted 14 February 2008 - 08:37 PM
pixkid@macmini~$ open -a Gimp.app bash: you want fries with that pixkid@macmini~$ echo No thank you, I am on a diet. bash: you make me feel unloved with your excuses pixkid@macmini~$ echo What? Are you insinuating that I do not eat your food? When did shells ever execute commands relevant to cooking? bash: shells duh ever think of seafood pixkid@macmini~$ echo No fair, stop searching puns, you have Lynx and Google to use! bash: ugh you humans are so annoying bash: logout [Process completed]