Making .gih ( Gimp Image Hose ) Brushes in GAP
Posted 28 May 2007 - 07:27 PM
How to make animated brushes (.gih - Gimp Image Hose brushes) using GAP.
Gimp Image Hose brushes, sometimes referred to as Image Pipe brushes, are one of the most underutilized features of Gimp. I imagine this is in part because of the seemingly complicated interface involved in saving them and in part because creating them manually, especially with any degree of complexity, is a chore.
Part of the credit for this tutorial goes to Punkie, who posted this thread in the help forum and inspired me to try doing this in GAP.
I confess that I do not fully understand all aspects of the interface to save such brushes. However, for what we are going to do, it isn't all that necessary.
As for creating brushes with more than a few layers, that is where using GAP (Gimp Animation Package) comes in.
Windows users can download GAP from here. Sorry, you can only get 2.2.0
Linux users, if you are on a packaged based distro, you can probably get it from the repository. However, chances are, the version in the repository is 2.2.0, which lacks a number of features available in 2.2.1, which you are likely gonna have to compile yourself from source, which, I believe, is available from the mirror sites on the Gimp.org download page.
In this tutorial we are going to make an "angular brush". This is a brush that actually rotates to follow the direction you are brushing, a very handy feature of Image Hose Brushes, with lots of creative possibilities.
Make a folder just for your brush.
Since our brush is going to rotate, make a square image. I like to make things oversized and then shrink later down to whatever size I want my brush to be. You don't have to do this, but I think it might make things smoother for rotational purposes. My image size is 300 x 300.
Save your image into the newly created folder using the following convention:
The "_000001.xcf" is the important part. GAP works with numbered images. Each frame of animation is a separate image, and each of these images can have their own layers. This is perhaps the most fundamental concept of GAP and is a bit tricky to understand at first, especially since not every frame in a GAP animation has to have the same number of layers. It can be very easy to get confused as to what you are doing.
Also GAP has its own system for keeping track of which layers it is dealing with. In each frame, the very top layer in the layerstack is layer "0", the next layer is "1", and so on. When you use the different commands of GAP, they often have a place that tells that command which layer in the layerstack to perform the command on. Be aware of this, or you may end up messing up a layer you didn't intend to.
Okay, from conversations with Punkie on the Gimptalk IRC chat channel, if you make an angular .gih brush with 71 frames, then each one will rotate 5 degrees (360 divided by 72 equals 5, however, you already have your first frame oriented at both zero and 360 degrees, so you only need it once at the "zero" position). My first experiments used 100 layers (the maximum number of "ranks" that can be used in a .gih brush - more about ranks later), but the 71 layers seems to work pretty good.
So, we need to duplicate our first image 70 more times, for a total of 71 frames. To do this, do Video>Frames Duplicate, and set the number of duplicates to 70. GAP will percolate for a bit and nothing much will seem to happen. You will still be looking at the first frame of your animated brush.
Remember, EACH FRAME is a separate image. You don't get new layers from Frames Duplicate. If you look in the folder that you made for your brush, you now have 71 separate .xcf files. Each one is a frame of animation and each one will, when we get to the final step of making our brush, become one of 71 layers in the final .gih file.
But what of the layers each one of those individual .xcf files has? When we do the final step, all the layers in each individual frame will be merged into one layer for that frame in in the final image. Don't worry, we will make sense of this a bit further on, if you don't understand this yet. However, it is of concern, depending on the type of brush you want to make.
There are two kinds of brushes in Gimp. Grayscale brushes and RGB brushes.
Grayscale brushes are grayscale images on a WHITE background. They can brush in any color you choose (and no...the white doesn't show in what you are painting, Gimp sees it as transparent).
RGB brushes paint exactly what the brush image is and you do NOT want them on a white background but on an alpha (transparent) background.
These next steps are for a grayscale brush that can paint in any color.
Lets test that we have all the frames we should, do Video>Go To>Last Frame. The number on the Title Bar of your canvas should now say something like "myimage_000071.xcf". You have jumped to the last frame of your animation. Notice the other entries in that menu: You can go to the first frame (where you were to begin with), or the next or previous frames, depending on what frame you are on, or you can do "Any Frame" which brings up a dialog where you can input the frame you want to jump to.
Now go back to your beginning frame with Video>Go To>First Frame.
From the Canvas menu, do Image>Duplicate. This gives us a new, untitled, blank canvas that is 300 x300.
These next steps are done on this untitled image. This will be the base image that we will copy as a new layer into the frames of our animation and rotate to make our angular .gih brush.
We need a layer that has transparency to make our brush on. There is more than one way to do this, I would simply make a new transparent layer, then delete the background layer.
Once you have done this, lets add some guides to help us center our brush image. Do Image>Guides>New Guide (by Percent). The default is 50%, which we don't need to change, and Horizontal. Basically just click OK. We get a horizontal guide across the exact middle of our canvas. Now do the same thing again, but pick "Vertical" from the drop down menu. We get a vertical guide down the middle of the canvas.
I am not gonna tell you what image to use to make your rotating brush. I am going to use the guides and some paths to make an arrow like the one below. You can do whatever you want.
Okay, now we have our source image for the next step. You can minimize this untitled canvas if you want. If you feel the need, save it. I almost never bother to, but if you need to make changes to it, you might feel safer saving it. Give it whatever title seems good, such as mybrush-base.xcf, and save it in the same folder as the rest of the brush files.
Step 7 (kinda long)
Now go back to your numbered canvas, the one that is the first frame of the animation.
Do Video>Move Path.
Set the handle to "Center".
Set your first move point to 150, 150
Check instant apply. You should now see the image you created for your brush in the preview window.
Down below the preview window is a slider for the video frame. Slide it all the way to the right so you are on the last frame of your animation (frame 71).
Click "Add Point".
Change the value in the rotational box to -355 (that's MINUS 355). You will see your brush image in the preview rotate to this new orientation. Just to make sure you have everything in order. Click the button that says "Previous Point", your image should return to its previous orientation.
Now click the button that says "Anim Preview." GAP Move Path will percolate for a minute, then spit out a shrunk down multilayer image of your animation and also a playback preview box. Click play and you should see your brush rotate continuously counter clockwise in the preview. If things are rotating clockwise, you didn't put in a minus number and your brush won't rotate correctly.
If the preview looks okay, close both it and the shrunk down image out. I suppose you could use the shrunk down preview file for your brush if it is okay for size. I am not sure what interpolation mode the preview generator uses. I have my default scaling option set to "Cubic", so it may just be using the default.
To make your move path take effect on your multi-frame image, click OK. GAP will percolate some more and copy the base image into a new layer in each frame .xcf of your 71 frames, rotating it by five degrees each time.
Step 7a (RGB -Brush) This step here is only necessary if you are making an RGB brush! If you are making a Grayscale Brush that can paint in any color, then skip this step!
Do Video>Frames Layer Delete. A dialog comes up. If you are on frame one of your animation (which you should be), then it will say the starting number of "1" and the ending number of "71". The layer number will be "0". Change the Layer number from zero to one. Then click OK. This will delete the white background layer in each individual frame image.
Now we need to make it into a single, multi-layer image. Do Video>Frames to Image, click OK in the dialog that comes up (you don't need to change anything), and again, after a bit, you will get a new, untitled, multi-layer image of your animated brush.
At this point, do Image>Scale Image and scale the thing down to whatever size you want. Make sure you use the "Cubic" option in the scale dialog to get the best quality.
Do Image>Mode>Grayscale. If you don't do this, then you won't be able to change colors when you paint, and the white background of your brush will show up when you are painting. If you are making an RGB brush, then leave the Image>Mode as RGB (you did Step 7a for RGB brushes ONLY...right? You don't have a white background on each layer...correct?)
Now save the file in your brushes folder with the .gih extension. Make sure you name your brush in this dialog and pick a good default spacing (you may have to fiddle with this, since there is no one "right" spacing to use). Leave the file open.
Set the Ranks to the same number as the number of layers you have (71) and change the mode from "Random" to "Angular".
Now fire up a new canvas, refresh your brushes, pick your new brush and give it a try! This is where you may want to play with the spacing slider to see what you think looks best. Once you figure out what that is, then in your .gih file (that is still open), do File>Save As and save it under the same name, make the necessary changes in the spacing and save it out.
Go back to your test canvas and do Edit>Clear, refresh your brushes and test things again to see how the new default spacing works.
If it is what you like...you are done!
....However, GAP can be used to make other types of .gih brushes as well. You can make a brush that changes sizes, either incrementally (Choose Incremental in the Ranks drop down menu) and use Gap to create different sizes of brush (Change the numbers for Width and Height instead of the ones for Rotate like we did here). You can also make different sized brushes and then, if you have a tablet, make a second ranking for "Pressure", so that if you press down while drawing, the brush changes size.
Also, you can make brushes that rotate in a pattern. Do this by placing the brush outside the rotational center of the brush canvas. An example of this can be found here.
Another possibility is to make brushes with "jitter", just like in the upcoming development version. You can't control the amount of jitter dynamically like you can in the development version, but you can make multiple brushes, each one with a different amount of jitter. You might even be able to tie this to the pressure option for a tablet, something that the development version doesn't do, I think. You can also create a sort of "patterned jitter" where the brush jitters, but only in a certain pre-defined area.
How can you do jitter brushes? By using the Grab Path feature of GAP. You can make an area inside the first frame of animation before you duplicate it. I like to make a rectangular selection in the center of the canvas, then save it to a channel. Turn the selection off, and turn on the eye for the channel. Then, using the path tool, click once outside this area for your first node, then, count and click inside the area, adding nodes to the path randomly. Be careful you don't accidentaly start a new path (best way is to zoom in on the area and click slowly and randomly all over inside the area, filling it with random path nodes.). When you get to where your next node would be the last frame (I used 100 frames for the jitter brush I made), close the path with the first node that you made "outside" the jitter area, then drag the node so it is inside the pre-defined area for jitter.
Here is a screenshot of the move path, this is actually an 800% enlargement. Actual image size is 100 x100. notice how there is one point in the upper left corner that kind of "sticks out"? This is the one I used to start and stop the path. Later, it was moved in with the others.
You can delete the channel, then do Video>Frames Duplicate and make 99 more copies of the frame for a total of 100.
Now, when you do your move path, you still choose Center for your handle, but instead of adding a point for the move path, you just click Grab Path. Your path will be visible in the window. If you have Instant Apply checked, your base image (your brush that you created, just like the arrow I made for the above part of the tute) will "snap" to the first node in the window. From there, do Anim Preview to see if things are working properly. You should see your brush image sort of "dance" all over inside the middle of the animation preview as it bounces from node to node in your path. If it works, then just click OK. From there the steps are pretty much the same as in the tutorial, EXCEPT when you save your .gih brush, choose the "Random" option for your brush. Now, when you brush, it will randomly select one of the 100 possible "mixed up" images you created with your random move path. The neat thing is, you can save your first frame with the path and re-use it for other brushes. Just vary the size of your canvas so your "randomized" brush doesn't go outside the canvas area. You can also scale or rotate your path to change the dispersment of the jitter.
Below is an example of the output from such a brush, the spacing of the brush was changed for the different strokes. It is an RGB brush. (I made two different sizes of the brush). Brush can be downloaded from here.
Posted 28 May 2007 - 08:51 PM
It's looking good ClayOgre. This is a sorely needed tutorial on a part of GIMP that is potentially extremely powerful but oh so hard to get one's head around. I have been seriously considering making some real natural brushes with this system one of those days, maybe even script a plugin for it in Python (point of a plugin would be to present the user with an interface to perform some of the most common things you would want to animate a brush for. Give a few squares in which you can draw/paste the brush images and tell the plugin to fill in the needed frames between them as nessesary. Another idea would be to let the user choose e.g. "rotate 360" degrees, tell it it should do it based on cursor direction and let the plugin perform the whole thing for you (basically what you describe in this tutorial only automated)... Would be exceptionally useful I think. It's also only a vivid dream, nothing more at this stage. Time, time ...
This tutorial will be much used I think. Great to see you put so much effort into it!
Posted 31 May 2007 - 03:07 PM
It's a very good tutorial, I learned a lot. Hadn't thought about the possibility of making your own Jitter brush, that could potentially be useful (I'm not really sure the dev version has a context dynamical setting for the jitter or does it? Haven't that computer on right now).
One thing I wondered about and which wasn't explained was why you have to have the angular-sensitive brush rotate counter-clockwise. I imagine it has to do in the way the brush reads the layer stack, but some more explanations and discussions around this would be appreciated.
Posted 31 May 2007 - 03:57 PM
To be honest, I don't know. I just know that if the thing goes clockwise, you get weird results. I think it is the layerstack thing, I just don't really have an idea, and I figured as long as you go CCW, it works. Most people, making a "manual" image pipe brush are gonna start at the bottom of the layerstack and add images going up. Not sure how GAP does this (I would think the same way...) This is probably one of those things that saulgoode probably has the answer stashed away in his bag of tricks.
As far as dynamic jitter...I dunno. I know there is a box and or slider to change the amount in the tool options window, but as for some kind on the fly control, I have no idea.
Posted 31 May 2007 - 06:55 PM
I didn't try it so it could not solve the issue but...
Did you try before saving as gih to make a copy and on the copy to run the "reverse layerstack script fu"?
(sorry i can't find script's link just now, not even sure about the author)
However quite good tutorial thank for sharing
Posted 31 May 2007 - 08:19 PM
No, but I did use the feature of GAP 2.2.1 which does the same thing: Frames Sequence Reverse. I found it simpler just to have the thing go counter clockwise to start with. As for the script-fu you mentioned...I only just recently became aware of it from an earlier post of yours.. It is in my scripts folder now. I think it is a saulgoode script. At least it is on the brickfilms website in the same place as the anim-settings one was.
Posted 01 June 2007 - 12:41 AM
I would imagine saulgoode puts his name someplace in the script header, so you should be able to verify it quite easily. :-)
Would be interesting to fully understand that clockwise issue.