TUTORIALS
Beginner
GIMPLite Quickies Use GIMP for your graphics needs without learning advanced computer graphics methods. Simple Floating Logo The famous "GIMP Floating Logos" rescued from the original GIMP web site and slightly modified to fit here. Even if you hate images of text on the web, this tutorial gives you some of the basic layer manipulation techniques. The knowledge can be applied to many many imaging projects and the logo *is* pretty cool ... Draw On Selections Borders Use the selection tools to draw simple or complex shapes. Paths (Bezier Selections) Use paths (bezier curves) like the GIMP Masters do. Quickmask Use Quickmask to make a vignette of your photos. Red Eye Removal Use the Channel Dialog in one method of removing red eye from photos. Straight Line Tutorial 'Tis somewhat rude. Perhaps the exact right frame of mind which to approach GIMP with though, at least the first few times ....
Intermediate
Drawing Shapes With Paths Make a dimensional box with paths (bezier curves) and gradients. Anti-Aliased Threshold Use curves and modes to transform your photo into a pen and ink watercolor like image. Film Grain Give your photos the appearence of film grain and learn about a new mode. Changing Background Color 1 Change the background color of your image and learn the magical properties of color2alpha. Changing Background Color 2 Change the background color of your image and learn the magical properties of Select By Color. Coloring A BW Sketch Color sketches anime style. 3D Floating Logo Another GIMP Floating Logo method, this one uses modes along with layers and select tools. Tileable Textures Learn about gradients, animated brushes and how to make tileable images as well. Simple Animations Learn how to work with GIMP's layers as animation frames. Custom Brushes Make custom brushes for your GIMP.
Expert
Make GIMP Image Pipes Rank and Dimension. GIMP's Image Pipes can do alot. Make GIMP Image Pipes 2 Even more options for pipe creation. Golden Text Make beautiful golden text and learn about the curves dialog and other color options. Sketch Effect Change your photo into a normal sketch. Photo To Sketch Change your photo into a nice painting or sketch. Draw A Paint Brush Put it all together and work your GIMP like the masters do. Creating Icons Use GIMP to create nice icons. Using GAP Learn the basics about using GAP, GIMP Animation Package. Advanced Animations Learn how to make an animation with GAP.
Photo Editing
Color2BW Converting Color Images to B&W. Selective Colorization Convert images to black and white and restore color selectively. Reducing CCD Noise Learn how to reduce the CCD Noise in photos. CCD Noise removal Use selective Gaussian blur to remove CCD Noise in photos. Contrast Mask Decrease problem contrast in photos. Sepia Toning Create a nice sepia photo from color images. Gaussian Blur Overlays Increase saturation and add a "dreamy" feel to your photos. GIMP Surgery "patch" blown out hightlights in your photos. Blending Exposures Increase dynamic range by combining different exposures of the same scene. "Smart" Sharpening Sharpen images without making noise more noticable.
Web
Perlotine Get your image in place with the help of perlotine and tables. Image Map Use GIMP to create a nice Image Map.
Script Authoring
Working With The Image Before you script, know what an image is and isn't and what a drawable is. Or at least be able to take a good guess about it ... Basic GIMP Perl Learn how to write simple perl scripts using the gimp-perl module (GNU/Linux users only). GIMP-Perl Debugged Ways to debug your gimp-perl scripts. GIMP Batch Mode A basic instruction about batch mode and GIMP. GIMP Script-Fu Write Scheme for GIMP. GIMP Script-Fu 2 Write More Scheme for GIMP.
GIMPLITE QUICKIES
Text and images Copyright (C) 2004 Carol Spears and may not be used without permission of the author.
Intention
So, you have GIMP installed on your computer, you need to make a quick change to an image for some project, but don't want to learn about computer graphics right now in order to get the image changed. Totally understandable. GIMP is a powerful image manipulator with many options and tools. However, it is quick and somewhat intuitive (after a time) for the small jobs as well. Hopefully, these quickies will help you with your quick problem and help you to stay friends with GIMP and ready for its more complex tools and methods later, when you have the time and inspiration. A couple of words about the images used here. The came from APOD, Astronomy Picture Ofthe Day. The screenshots were taken on my desktop which is sporting this APOD image. All you should need to know to start here is how to find your image and open it. File -> Open.
Problem: you have a huge image and you want to put it nicely for viewing on a web page. GIMP is a quick solution. Our example image is this beauty m51_hallas_big.jpg from APOD. The first thing that you might notice is that GIMP opens the image at a logical size for viewing. So, if your image is really big (like the sample image) it will display it zoomed out until it fits nicely. You can tell if GIMP has done this by the percentage number in the title bar. (you can click on the little screenshot to see the full view of the screenshot) Just because it looks right in this "View" doesn't mean anything. The other thing to look at in the titlebar is the mode. If it says RGB in the title bar, you are fine. If it says Indexed or grayscale there, you should read the Change the Mode Quickie.
Image entry in the menu and the sub menu from the screenshot should reveal itself. Click on "Scale Image...". When ever you click an option from the menu that has ... behind it, expect another dialog. This time, you should get the "Scale Image Dialog". If you have a desired width, put it in the dialog at the top where it says "New Width". If you don't have such a number in mind, you can steal the width of GIMP's default image size, which is 256 pixels. This is demonstrated in this screenshot. You can see the image that this scale dialog produced here. Perhaps you want your image to look more like a 4x6 inch photo on most image rendering web browsers. Simply switch the units to "inches" and put 4 inches in the height box (opting for smaller than 4x6 rather than bigger). You can see this dialog here. The image this dialog produced here. Let GIMP choose the other dimension length for you. Meaning, it will take more image knowledge to change both width and height and have it look correct. So only change one and let GIMP change the rest. To change the other length see the crop quickie.
You can make your jpegs smaller without changing the pixel width of the image. Actually you can change the weight of the image a lot. I used an(other) image from APOD. The original image is huge (3000 pixels wide) so I also made a smaller (pixel width) image available. To prepare this image for the web, you should first reduce the image to a better width and height for web viewing as described in the scale quickie. Right click on the properly scaled image and follow the menus <Image> File -> Save As.... The Save Dialog will pop up. I generally type the filename I want into the text box, but the Extension drop menu can tell you the available file formats (depending on the libraries you have installed and the conditions of the image you are trying to save). If GIMP complains right now, or if "JPEG" is grayed out in the Extensions menu you should just cancel out of everything and step through the Change the Mode Quickie.
In the JPEG Save Dialog, you can opt for GIMP defaults which reduce the size quite a bit, without hurting the visual quality in a way that I can detect. This would be the safest and quickest thing to do. If you would like to make it smaller still, make sure that the "Preview" toggle is on and then watch the image area and change the compression level by moving the "Quality" slider down. You can see the quality of the image changing, especially towards the leftmost end of the slider. Here is a screenshot of me doing this very thing. As you can see, very small is also very bad. I have a screenshot of me setting the Quality slider to a more acceptable level here. I have not been showing the actual jpegs I created so that we could end this quickie with a race. Clicking this page should "race" these jpegs to a web page (the first time you see an image in most browsers, you are also waiting for it to write to the cache, so the first time is the worst). With my cable modem, I was unable to see a difference in the load time, but the difference in what you actually see is fairly interesting.
Crop An Image
Many reasons to need to crop an image. Making rectangles square, or making squares into rectangles. Cutting alot of useless background to bring out the subject better. etc. To get to the crop tool, you can either push the button on the toolbox or right click on the image and follow the menu <Image> Tools -> Transform Tools -> Crop & Resize. This will change the cursor and allow you to click and drag a rectangular shape. The button in the toolbox is the nicest way to get to any of the tools. I have chosen one of the huge and beautiful APOD images, ngc6369 heritage. I always click on the approximate upper left corner and drag to the lower right corner. You don't need to worry about being accurate on this first swipe with the crop tool, since a little dialog will pop up and you can make a better choice for your new borders there..
After completeing the click and drag motion, a little "Crop & Resize Information Dialog" (shown above also) pops up, telling you information about the borders that were defined in the click and drag. We will have to change all of the numbers. If you would like to make this rectangular image square, you should find the width and height from the Get Image Information Quickie. Use the smallest of the two lengths to determine the size of the square. In my 300 x 225 pixel image, the largest square I can get is 225 x 225 pixels, and I will need to make sure the Y origin is 0. At that point, I use the image and the squares to get the best part of the image for the area. The upper right and lower left crop squares will move the marked area. The other two (upper left and lower right) will change the dimensions of the marked area, so be careful. I have a screenshot of this, right after I fixed the width and height and the Y origin, but before the final positoning. The arrows show the move points. I decided that the image looked the best with the X Origin at 42. The final image appears here.
This window will tell you the pixel lengths. Right click on the image and follow <Image> View > Info Window... Here is a screenshot of a calculator which also gives lots of good information. I got another image from APOD It is pretty big. (Not as big as Saturn though) You can see in the dialog above, it is 2241 x 1548 pixels. If you are just making a square out of a rectangle, like in the Crop An Image Quickie, you need only to open the dialog and find the lesser length and use that as described. Since this is very little information, and definately not enough to fill the space between the menu thumbnail and the dialog screenshot in my layout, I thought I would run through some calculator exercises that might help you to meet your image needs. It is nice to have images appear on a browser window as a photo would. Photos online appear to be 4x6 inches when scaled to 288x432 pixels (72 dpi for many monitors). There is a problem, however, if you try to scale this image. The ratio of width to length of the original does not match the ratio of the photo. So, to make the scaled image the correct size crop 10 pixels from the height. For the sample image, it was best to crop 10 pixels off from the top. The final image should "appear" as a 6x4 inch photo on most monitors.
There will be problems whenever mixing scanned photos with digital photos and also with scanned negatives. Modern film developing machines automatically crop one half of an inch off from each image -- the rumor is that the photo printing machines match a certain style of camera view. If you are preparing an image to be printed on a machine like this; or if you are planning on a gallery where the images are from different sources, some intelligent cropping to fit the best size for the medium you have chosen will be a plus. If this is confusing; please blame the photo printing industry and not GIMP. You can change the Resolution of your image as well, using the same methods as we used in the Scale, although, in my somewhat limited use, the issue is more about how many pixels. Let's say you want to get this image printed at the photo lab. 300 pixels for every inch is preferred. This original image will print easily as a 7 x 5 photo. 2241px/300ppi = 7.47in. Get out your calculator for the short side. 1548/300 = _. There is another brutal fact you should come to terms with if you are new to graphics and computers. Just because it looks good on the screen (the image from before) doesn't mean that it will print that nicely. I tried to emulate how this image would appear printed at 300dpi here. Sorry. There are some options, for instance my friend printed images and then scanned them back in. Terrible business!
As with anything else, images come in different kinds and serve different purposes. Sometimes, a small size is important (for web sites) and at other times, retaining a high colour depth in all its glory (a family portrait) is what you want. GIMP can handle all of this, and more, primarily by converting between three fundamental modes, as seen in this menu. In order to switch your image to one of these modes, you open it and follow that menu and click the mode you want. RGB - This is the default mode, used for high quality rich colour images. This is also the mode to do most of your image work with including scaling, cropping and even flipping as it gives the computer more information to work with. This extra information also makes RGB Mode the largest to store as a result.
A little bit of detail if you are interested. Each pixel or point when in this mode consists of three different components. R->Red, G->Green, B->Blue. Each of these in turn can have an intensity value of 0-255. So, at every pixel, what you see is an additive combination of these three components. All these combinations result in a way to represent millions of colours.
As an example to practice with images have been provided in various sizes and formats. Indexed images of different sizes: from a very old APOD a small gif and a larger gif of the same image from a later APOD. Also the same image in RGB as provided by Earth Observatory a smaller version and a huge version. Indexed - This is the mode usually used when file size is of concern, or when you are working with images with few colours. It involves using a fixed number of colours, 256 or less, at each point to represent the colour at that point. GIMP defaults to attempting to figure out an "optimum palette" to best represent your image. Try it, you can undo it if you don't like the results, or use a custom palette or more colours.
As you might expect, since the information needed to represent the colour at each pixel is less, the file size is a lot smaller. However, sometimes, there will be options in the various menus that seem to have been "greyed" out for no apparent reason. This usually means the filter or option cannot be applied when your image is in its current mode. Changing the mode to RGB as outlined above should solve this issue. If that doesn't work either, perhaps the option you're trying requires your layer to have the ability to be transparent. This can be done just as easily via (Image)->Layer->Transparency->Add Alpha Channel.
Grayscale - In case you want to convert your brilliant colour image to something that's black and white (with a lot of shades of grey), this is one of the easiest ways in which to do it. Some photos do look a lot fancier when displayed in grayscale. Again, if you're interested in some detail, this is achieved by taking the RGB values at the pixels in your image, and suitably weighted averaging them to get an intensity at that point. There is no need to convert an image to a specific mode before saving it in your favourite format, as GIMP is smart enough to export.
Flip An Image
When you need the person in the photo looking in the other direction, or you need to top of the image to be the bottom. Mirroring the image (sort of). Right click on the image and follow the menus <Image> Tools -> Transform Tools -> Flip, or use the button on the toolbox. Using another APOD image I demonstrated all of the flips on this image. You might get bored before it is over ....
The tool used as is (the default) will do this to an image. If you double click on the button, up will pop the means to flip images vertically as well. I did just that on this image. For a really big finish, I flipped this image both ways. At least it is such a cool image for all of this silliness. The flips are all displayed on one page for you, here. One might ask themselves, useful? or filler for a pre-established format?
Rotate An Image
Let's say you turned your brand new digital camera to get a vertical shot, now some of your images are on their sides. Right click on the image, and follow the menus <Image> Image -> Transforms -> Rotate -> 90 degrees (or 270 depending on the orientation). Using an APOD image. I rotated it once to demonstrate. 90 degrees CCW.
Intention
On this page, the first section of our ever growing (?) collection of tutorials, I will demonstrate the basic operation you will need to perform over and over again in your life as a computer artist: Generate isolated parts of a picture and combine them with a random background. What we want to achieve in this example is to generate a 3-dimensional text logo flying (and movable) over the background (a simple uni-color layer in our case, but you will easily see that you could use any other (stack of) layers/images instead. Start with a plain white picture, black as the foreground color and open the layer dialog!
Adding text
Use the text tool to add some text. You will get a new text layer which you can also see if you look at the layers dialog. You can use the move tool to move the text where you like to have it. Then merge it with the white layer below by choosing Merge Down from the Layer menu. You should now have one layer with black text on white background. Using <Image> Layer -> Colors -> Invert you will achieve something like the picture above.
Adding colors
First of all: Blur the image a bit (Gaussian blur at 5 may be a good start). Now add a new layer to the image with the help of the New Layer button in the layers dialog. Choose it to be white. It will be created above the just made text layer effectively hiding it. It will be active which can be seen from the fact that it has a blue background in the layers dialog. Click some times on the eye symbol to see how you can make a layer invisible and make the other layer active by clicking on its small preview in the layer dialog. At the end, leave the new white layer visible and active. Use the plasma plugin to make this layer a little colorful (Yes, you are invited to experiment with the parameters...). The layer dialog should look something like this now:
Bumpmapping
It's getting funny now: Use the bumpmap plugin with the blurred text layer as a bumpmap on the plasma layer. You can play with the other parameters, but they have sensible defaults. You'll get an image like the one above. Now (still on the plasma layer) choose Add layer mask from the layer dialog menu. Choose the mask to be white. Nothing will change on the image for now, but the layer dialog will look like this:
You can toggle whether a layers mask or the actual picture is active by clicking on their previews in the layers dialog.
Now activate the text layer again. (you don't have to make the layers on top invisible to work on this layer. It's enough that you activate it in the layers dialog.) Now do <Image> Edit -> Copy. Make sure you have the mask of the top layer selected and the layer is activated. Choose <Image> Edit -> Paste. You will again get a floating selection, shown in the layer dialog like this:
Use the layer dialog menu to Anchor Layer, which will anchor the floating selection into the previous activated layer (which is the mask of the plasma layer in our case). This will leave you with the following scenario:
Now add a new layer and fill it with some color (e.g. with the help of the bucket fill tool) and use Raise Layer or Lower Layer from the layer dialog menu to achieve something like this:
Now you'll see that the image of the logo isn't very sharp. We'll change this now. Make sure you have selected the plasma layer's mask and open <Image> Layers -> Colors -> Levels. This tool is one of the most important tools you have! Play with the little triangles you'll see in the two grey gradients and watch their effect on the image. For now, try to achieve something like the following:
What we do here is making the border of the mask sharper, and by that means, sharpening the whole picture (the area which is neither 100% opaque nor transparent will become smaller). But we can easily avoid the picture getting pixel-steps by leaving still a smooth transition between opaque and transparent parts of the layer. (If you didn't realize it by now I bet you did - the layer mask works in such a way that all black parts of the mask will become transparent parts of the layer and all white parts will stay opaque (with smooth transitions realized by values of grey).
Creating a drop-shadow
Using the layer menu you will have noticed the entry Duplicate Layer. Use this now. Then use Apply Layer Mask and Lower Layer which should leave you with something like this:
Make sure you check the Keep Transparency option (the little box next to the layer mode) and then fill that duplicated layer with black. You can paint over the text with a paint tool or simply drag a black color from the color selector and drop it over the image. You do not have to be careful: the Keep Transparency button will let you paint only on opaque parts of the image. This will give you:
Now make sure you uncheck the button again and move the layer some pixels to the right and downwards. You can move it with the Move tool while pressing Shift so that it moves the current layer instead of picking a new one. (Alternatively, can use <Image> Layer -> Transform -> Offset and enter a small offset for both X and Y: this will offset the contents of the layer without moving the layer itself.) Then blur your layer and adjust the transparency with the slider so the background will shine through: You've just generated a so-called drop shadow, which greatly enhances the 3D effect and is used in very many places.
That's it! Now have a lot of fun making flying logos! The original tutorial can be found here.
BORDERS ON SELECTIONS
Text and images Copyright (C) 2002 Francisco Bustamante Hempe and may not be used without permission of the author.
Intention
Since GIMP is an image manipulation program and not a painting program it doesn't include tools to draw shapes like squares and circles. However this doesn't mean you can't paint them, in fact there are some interesting options regarding this subject when it comes to GIMP. The solution is to use the selection stroking capabilities of GIMP.
This option can be accesed on the image menu (right button click on the image), by going to <Image> Edit -> Stroke Selection.
Step 1
Before doing that however we need to make a selection with the shape we want. There are several ways to make a selection, including all the tools in red shown above and select by color as explained on Selecting and removing one color . When using the tools, holding shift at the beggining of the selection process will add the selection to what is already selected, while holding the control key will substract from it.
Step 2
Use the selection tools to create a selection with the desired shape.
Step 3
After you have the selection, choose a brush from the brush selection dialog. Choose also a color and you can play with the spacing option for the brush. Brush selection dialog
Step 4
When all the options are selected you can click on <Image> Edit -> Stroke. You will get a dialog allowing you to set many options for stroking your selection, including dashed lines and other fancy features. If you select Stroke Using a Paint Tool, you will be able to use the brush that you have selected.
Step 5
When all the options are selected you can finally click on OK. Using a fuzzy brush and selecting a blue color here is the result for the selection made above.
Examples
Playing around with the spacing options in the brush selection dialog, the color or using one of the animated brushes you can get very interesting results.. here are some examples. The original tutorial can be found here.
Intention
The Path tool (previously known as Bezier Selection) is a powerful tool in GIMP. The rectangle- and ellipse-selections are not very flexible if you happen to need something more special. And since many of us GIMPers don't have a graphics tablet, it's not so easy to make the mouse pointer move the way you want. The paths can solve the problem by using smooth mathematical curves instead your own shaky mouse trail. Paths are also very useful when used with gradient fills, see Drawing Shapes with Bezier for more information on this great tool.
What is it?
The Path tool can make complex selections by specifying certain points that are connected together with a curve. So to make a box you would specify four points, one for each corner of the box. Example in image above. The great thing is the corners don't have to be 90 degrees. In older GIMP versions (1.2.x), you had to close all paths by joining the last point of the path to the first one. This is not necessary anymore in 2.0 and later versions, but this is still useful to create closed shapes such as a box. So after creating the fourth point, press and hold the Ctrl key and click on the first point to close the path. Of course you can have as many points as you need. Finally, click the "Stroke Path" button (in the Path Options dialog) or use the menu Edit>Stroke Path... to draw the new shape. You can also use the button "Create Selection from Path" if you want to have a selection that you can fill or stroke.
Straight lines alone are a useful thing, but it's not all. Actually they are not lines but curves. Cool anti-aliased smooth curves. The curves can be modified quite flexibly by adjusting the 'handles' of the nearest points. 'What handles?' you say... See the image above? The small circles are those familiar points we used with the box in the previous section. The little boxes are those handles. The handles are not visible by default, you must drag them 'out' from a point. To make the handles visible 1. click to a point to make it active, 2. while pressing the Ctrl key, click again on the same point and 3. drag the handles out with the mousebutton still pressed down. You notice the curves between the points are not straight anymore. You can control the shapes by dragging the handles around.
A Few Tips
Always before modifying any points or handles, click the handle or a point to make it active. To have a smooth curve, both handles should be aligned at each point. Press Shift while dragging a handle to ensure that the other one remains aligned. A path can have multiple components. If you have closed a path, you can create a new component by clicking where you want to place the first point of the new component. If you want to create several components without closing them, press Shift and click where you want to start a new one. When you are satisfied with the shape, you can use Stroke Path or Create Selection from Path. The default GIMP installation creates a dock containing the tabs "Layers, Channels, Paths, Undo". Click on the Paths tab to manage your paths. The original tutorial can be found here. It was updated for GIMP 2.0 by Raphal Quinet.
Bezier Selection Bezier selection is a powerful tool in The Gimp. The rectangle- and ellipse-selections are not very flexible if you happen to need something more special. And since many of us gimpers don't have a graphics tablet, it's not so easy to make the mouse pointer move the way you want. Bezier selection fixes the problem by using smooth mathematical curves instead your own shaky mouse trail. Beziers are also very useful when used with gradient fills, see "Drawing Shapes with Bezier" for more information on this great tool. What is it? Bezier selection is a tool to make complex selections by specifying certain points that are connected together with a curve. So to make a box you would specify four points, one for each corner of the box. Example is on the right side. The great thing is the corners don't have to be 90 degrees. After selecting the fourth point, click on the first point to close the curve (beziers have to be closed - at least at the moment in the current Gimp). Finally click inside our 'box' to turn it into a selection. Of course you can have as many points as you need. Modifying the curves Straight lines alone are a useful thing, but it's not all. Actually they are not lines but curves. Cool anti-aliased smooth curves. The curves can be modified quite flexibly by adjusting the 'handles' of the nearest points. 'What handles?' you say... See the image on the right? The small circles are those familiar points we used with the box in the previous section. The little boxes are those handles. The handles are not visible by default, you must drag them 'out' from a point. To make the handles visible 1. click to a point to make it active, 2. click again on the same point and 3. drag the handles out with the mousebutton still pressed down. You notice the curves between the points are not straight anymore. You can control the shapes by dragging the handles around. A Few Tips 1. Always before modifying any points or handles, click the handle or a point to make it active 2. To move just one handle and leave the opposite side in its place, click on the handle to activate it and press shift while dragging it 3. To move the points around, activate a point (or its handle) and drag it around with ctrl pressed down 4. When you are satisfied with the shape, click inside the curves to turn it into a selection
QUICKMASK TUTORIAL
Text and images Copyright (C) 2002 Zach Beane and may not be used without permission of the author.
Intention
This tutorial shows how you can do vignette effects using a feature of GIMP called QuickMask. QuickMask is a convenient way to modify selections using pixel-changing tools such as the paintbrush, eraser, or any plug-in filter. It lets you make very precise adjustments to your selections. This tutorial doesn't use QuickMask for complex masking; it's intended to show how you can use it to create quick and easy vignette effects.
Step 1
For your first step, load up an image. Any image will do. GIMP 1.1.7, a development version of GIMP, introduced QuickMask. The QuickMask control button is located at the lower-left side of the image.
Step 2
First, make a rectangular selection around the edge of the image. Then click on the redbordered QuickMask icon in the lower-left corner of your image.
Step 3
After you click the red QuickMask button, a translucent red mask appears around your selection. This red mask represents the outside of your selection. When you click the dashed QuickMask button to go back into normal selection mode, anything red will not be selected, and anything clear will be. So, let's start playing with this mask. First, right click on the image and select <Image> Filters -> Distorts -> Waves from the menu. Apply the filter, and watch what happens to the mask.
Step 4
The mask gets all wavy. Let's add one more effect: <Image> Filters -> Blur -> Gaussian Blur (RLE).
Step 5
Now that there is a soft edge on the mask, click the dashed QuickMask button to convert the mask back into a selection.
Step 6
See how the selection follows the mask? This is a powerful feature of QuickMask. You can use it to modify any existing selection, and you can even use it to create new selections. Our last step is to use <Image> Select -> Invert and <Image> Edit -> Fill with BG Color. The result, a soft white fade into the background, is shown in the final step.
Final
And there you have it. Some more examples are listed below. Happy GIMPing!
Examples
The above image used <Image> Filters -> Noise -> Spread, with horizontal and vertical settings at 11, to get the effect.
I used some blurring and the <Image> Filters -> Distorts -> Newsprint plugin to get this effect.
As in the tutorial, this one used Waves, but instead of blurring, I used <Image> Filters -> Blur > Pixelize instead. The original tutorial can be found here.
Intention
It used to be that the photos with red eye weren't really worth fixing as only cheesy cameras had the flash built in and underneath the red eyes was a crappy photo. Well, welcome to the future when you can get a pretty good image from a camera with the flash built in. They do not have a button that works to prevent this yet, so don't even try it. The best way to fix red eye on photos is to have those intense people look at the photographers shoulder. The cause of red eye is the flash reflecting from the back of the eye and into the lens. So, until this lovely child is able to understand "look at my shoulder" it is good to know that red eye can be fixed, somewhat. I learned the following method from tigert while lurking on the irc late late one night.
Step 1
I zoomed in on the image, 4:1 ratio, as this is almost pixel by pixel work. I ended up using the 5 x 5 fuzzy brush that came with the GIMP tarball. As usual, your choice depends on the resolution of your image. A fuzzy brush is highly recommended. On this web sized image, the 3 x 3 fuzzy brush didn't work fast enough. As always, you can <Image> Edit -> Undo until you make the right selections.
Step 2
A long time ago, someone suggested on the gimp-user list that the Layers, Channels and Paths Dialog always remain open while you use GIMP. Some three years later, I still follow and give this advice. So, if your Layers,Channels and Paths Dialog is not open, open it and leave it open. Select the Channels Tab. Deactivate the Green and Blue Channels by clicking to the right of the thumbnails in the dialog window. The image should still look like the screenshot of the close up in step 1. If it looks all red, you have just turned the view of the color off. (burning the red eye area will not work if the Layers,Channels and Paths dialog is set up that way, I happen to know).
Step 3
Make certain you have a good brush selected (for this image I used the 5 x 5 fuzzy) Then select the Dodge and Burn Tool. Double click on the button to get the Tool Options dialog. My dialog
defaults to dodge and midtones, for this project, choose burn and hightlights (as illustrated). Touch all of the red in the eyes with the burn tool. I think that I used the burn tool on the midtones just a little bit also. GIMP doesn't have a magic button to fix red eyes with, but it has the tools. It has been my experience that each image is slightly different and I sort of like the control that GIMP gives you ... tigert warned that this method can leave the white spots in the eyes slightly green. I have found this to be true, however so far it hasn't been enough green to worry about. Given a photo where the green will make a difference, you can use the same tool combination on the green channel, just move the opacity slider to a smaller percentage. <Image> Edit -> Undo until you get it right.
Final
... looking so much better! The very best fix, of course would be to prevent it from happening. Due to the nature of the problem, my guess is that it will be the same people over and over again with this problem. Some personalities have no problem looking deeply into the camera lens (like this beautiful baby for instance) and maintaining the gaze through the flash. My guess is that as soon as these people know what is going on, they can fix it themselves. Other personalities have other portrait problems. There is a small handful of people who have no problem looking into the camera lens, but anticipate the flash and blink at the wrong moment. This causes the portrait to look like the object is starting to sneeze. (this is what happens to me) If you know of a method to prevent this, please email me.
What a cute baby. This is Maurits and his baby. He is one of a growing list of developers that are changing their babies while working on GIMP. I watched work on WinGIMP occuring between diaper changings and feedings also. *chuckle*
Intention
This tutorial shows you how you can do straight lines with GIMP, using a feature called the Shift Key. Straight lines are a convenient way to make things that aren't so terribly affected by the imprecision of a mouse or tablet, and to take advantage of the power of a computer to make things look neat and orderly. This tutorial doesn't use Straight Lines for complex tasks; its intended to show how you can use it to create quick and easy line effects.
Step 1
The invention called the typewriter introduced the Shift Key. You generally have 2 of them on your keyboard. They look something like the picture on the left. They are located on the left and right sides of your keyboard. The other invention, called the Mouse, was invented by Douglas C. Engelbart in 1970. These come in different varieties, but always have at least one button located on them. They are located on your desk, or sometimes on a mouse pad.
Step 2
Step 3
Then click on the paintbrush. Any of the red-highlighted tools on the above toolbox can do lines.
Step 4
After you click the paintbrush tool, you can click the image. A single dot will appear on the screen. The size of this dot represents the current brush size, which you can change in the Brush Dialog. Now, lets start drawing a line. Hold down the Shift button, and keep it down.
Step 5
After you have a starting point, and have held down the Shift Key, you'll see a line like above if you're running GIMP version 1.2.x or later. This feature was not present in GIMP version 1.0.4. However, the next step works the same way. Press the first button on the Mouse (the leftmost one usually) and then let it go. During that whole "click" of the Mouse button, you need to keep the Shift Key held down.
Final
See how the line is drawn on top of the preview? This is a powerful feature of the Paint Brush. You can use it with any of the tools shown in step 4, or even draw more lines at the end of this one. Our last step is to let go of the Shift key. And there you have it. Some more examples are shown below. Questions? Comments? Let me know. Happy GIMPing! Seth
Examples
This one I rendered a grid, and then used the Smudge Tool with a low spacing and a slightly larger brush.
This one I used the Clone tool, and set the source to "Maple Leaves" pattern.
This one I rendered a plasma cloud, and used the Erase Tool with a square brush.
This one I used the Dodge tool on the top and left of a blue box, then used the burn tool on the right and bottom. The original tutorial can be found here.
Intention
The Path Tool (replacing the old Bezier Selection tool) can be used in many creative ways. Maybe the best thing in it is the smooth, beautiful curves it produces. But you can also use paths to create different polygonal shapes if you don't 'pull out the handles'. Polygonal shapes are especially useful when painting some geometric objects, as you can draw one side at a time (into different layers if you want).
This tutorial is about making simple geometrical shapes with GIMP. I will concentrate on the Path tool since I find it so useful for this purpose. I hope you get some help and new stuff to put in your GIMP Tricks Sack :) I personally use this technique for nearly all my work. Notice! This is not a 'back to basics' -tutorial. You should be familiar with GIMP's dialogs and menus. I was thinking about this, and I did not want to make this an 'entry level' thing, basically to avoid bloating this too big and duplicating other people's work. Paths are covered in my other tutorial, and I recommend you to read it before going further if you find the material here confusing. If you are new to GIMP I suggest you to go to the GIMP homepage in www.gimp.org and first read through the Documentation section there.
1. Left side
Now create a new transparent layer, and name it Left_side so you know what layer I'll talk about later on. Make sure you have the new layer active by checking the layers-dialog. If it is not selected, click the layer's name in the dialog. Imagine the blue cube on the right side into your canvas, we'll be doing side #1 now.
Choose the Path tool and make something like the side #1 on the blue cube, think about the perspective. (If this causes you trouble, don't worry. You will learn by experience). You can adjust the points' places if you can't get them right at the first try, see the Path tutorial for more information on that. Your path should look something like the one on the right. Once you are satisfied with your "box", convert it to a selection using the button "Create Selection from Path" (in the Path Options dialog) or using "Selection to Path" (in the Paths tab).
Next we must choose some nice colors for our gradient, choose white for the foreground color and some dark-blue for the background (we are making a blue box, remember?) Something like that on the image nearby.
Select the gradient-fill tool and, starting from the top-left of the selection, 'drag' the gradient quite far down-right (see the arrow in the image. This way you get a quite lightcolored face for the cube, and it is just what we want here. We also want the lighter end of the gradient to be near our imaginative light source. (The light was coming from the left)
2. Right side
Now on to the right side, side #2. Create a new transparent layer and name it Right_side. Use the Path Tool and try to make the right side of the cube and turn it into a selection. Take the Gradient Tool again and, still with the same colors, make a gradient from farther upleft to near the selection's lower-right corner (see image on right). This way we get a darker gradient suitable for the shadow-side. Hint! Be careful with the edges. You don't want to leave any holes so the background can be seen through... It's better to overlap the lower layer a bit than leave a space between them.
3. Top side
Our final ultimate task is to create the top, side #3. Again, create a new transparent layer and name it (who quessed? :) Top_side.
Now you probably know we want to make yet another path and this time the gradient has to be even lighter than in the first side. So I suggest you lighten the dark blue color a fair amount, it's easier to get a light gradient that way. This time you pull the gradient from left to right, according the arrow in the picture. Once you find the shading look good, you can flatten the image and our little tutorial-cube is finished. Now apply for your 'Cube GIMP Licence' from the nearest GIMP Station ;)
4. Finished Work
Now you have a cool image of a Light-Source-Shaded Cube. You can choose <Image> Image -> Flatten Image to merge the layers togerher so you can save as jpeg or any other format than xcf. Or, better still, from the layers dialog, make the background invisible and choose <Image> Image -> Merge Visible Layers so you will have the background on a separate layer and you can work further on it if you like. The next thing is to start using the geometrical shapes as building blocks to make things. And you can twist the beziers to make a bit more fancy stuff... I have provided the xcf-file for the image we just created, if you want to experiment with it, although you should be perfectly able to do just as good yourself. Thanks for your interest. tigert The original tutorial can be found here. It was updated for GIMP 2.0 by Raphal Quinet.
Intention
The threshold plug-in works by dividing the image into two parts, dark and light, producing a 2 color image. This is often not the desired result, for some images anti-aliasing is needed, but the threshold plug-in cannot provide that. With a little utilization of the curves plug-in, we get nice results.
On the left you we see the original image that is about to be thresholded, and on the right side we see the result. The default settings for the Threshold plug-in were used (<Image> Layers -> Colors -> Threshold). The resulting image is very blocky and aliased.
First duplicate the image layer by going to the layers dialog, making sure the image layer is selected, and clicking the duplicate button (fourth from the left). We can use the original layer for some color tricks later. Now the next thing is to desaturate the image (<Image> Layers -> Colors -> Desaturate). This way the colors will not interfere with the fake thresholding. When the layer is grayscale, select the curves editor (<Image> Layers -> Colors -> Curves). Now we can play with the Value "channel". The image on the left displays the settings used for the example image. The space between the two dots determines how much aa the resulting image will have. The wider the gap, the more grayscale values it will have, and vice versa. The resulting image can be seen on the right.
A neat addition
If you now take the original image layer, move it over the new one (make sure it has an alpha channel), and change its mode to "Color" in the layers dialog, you get nice results displayed above. The original tutorial can be found here.
Intention
Real-world images have lots of noise: film grain, scanner lines, CCD noise, paper texture, and just about anything else you can imagine. Computer-generated images, on the other hand, tend to be too real. If you need to make computer-generated images look like real-world ones, then this tutorial is for you.
Perhaps you've rendered a gorgeous 3D scene, but want to make it look more like a photograph. Perhaps you're compositing two different photos, and need make the grain match. Or maybe you're just perverse.
(GIMP pattern file) Some good ways of making tileable patterns include Make Seamless, the Resynthesizer and Homogenizer, mirroring, and hand-editing. You'll have to experiment a bit. In the following example, we'll use a weird, vertically-striped noise pattern. It looks like some kind of scanner noise, or perhaps an artifact of old newsprint.
First, desaturate the image. You can do this using <Image> Image -> Colors -> Desaturate or the Desaturate filter provided with the MathMap plugin.(The latter actually returns the luminosity of an image, not a desaturated version. Technically, it's better, but it's unnecessary for most images.)
Step 2
Next add a new layer to the image, and use the bucket to fill it with your tileable noise.
Step 3
Position the noise layer above the image layer, and set the mode to Grain Merge.
Step 4
So far, so good. But the noise is too strong in the shadows and highlights of the image. To demphasize it, we can use a layer mask. First, add a layer mask to the noise layer. Then, make a copy of the image, gaussian blur it with a radius of 15 pixels, and paste the blurred image into the layer mask. Use <Image> Image -> Colors -> Invert to swap bright for dark. This will cause the grain to show through strongly in the shadows and midtones, but not in the highlights.
Step 5
Next, use <Image> Image -> Colors -> Curves to adjust the value of the layer mask. We want to make the midtones bright, and the shadows and hightlights dark. You can adjust the curves to taste. Curves Dialog This increases the grain in the midtones, and reduces it elsewhere. Here's the Layers, Channels & Paths dialog for the finished image.
Related Techniques
You can use various brushes in the mask layer to selectively edit the grain. You can also use the bucket tool in Pattern Fill, Grain Merge mode to fill a selection with grain directly. Many kinds of noise can be created using <Image> Filters -> Noise -> Scatter HSV. You can apply this directly to an image, or to a film grain pattern. To denoise an image, try <Image> Filters -> Blur -> Selective Guassian Blur. It's slow, but very nifty.
Intention
to This tutorial shows you how you can effeciently replace the background of an image with another in GIMP, through the use of the color to alpha plug-in. The aim is to show the advantages of using the color to alpha plug-in over selection-based techniques. To illustrate this, this tutorial will use the above images as source and destination. This tutorial doesn't address the complexities of handling real-world photos in this manner, but does briefly discuss it at the end.
The common approach to doing many things in GIMP is to first get a good selection. However, when removing an anti-aliased object from its background is not a good idea, as shown above. You'll note that each of the three zoomed in selections above have varying amounts of the green-blue mix selected. When these are filled, we are left with flat black and slightly blueishgreen pixels between them, or no transition to black at all. Compare each with the target image below. The left one has a blue border around it. This looks somewhat neat, but not what we're going for. The middle one is close, but there are some ugly visble pixels still. You can try getting rid of all the ugly pixels, but then you'll end up with something jagged like on the right. You can spend hours trying to find something that will work perfectly, but you won't. Anything short of the rightmost image has some blue in the pixel, which will stick out. You can go too far, and blend it back to something close, but this is time consuming. Instead, may I suggest the rest of the tutorial?
Step 1
The first step is to activate the color to alpha plug-in. Its menu location is <image> Filters -> Colors -> Color To Alpha, where <image> means to right click on the image. If its grayed-out, it means that you have an indexed image. If its not there, upgrade your gimp to 1.2.x.
Step 2
Step 3
When you used the color picker to select the background, a window with the color popped up. Click, hold, and drag from the color portion of this window to the color portion of the Color To Alpha plug-in. If using Gimp for Windows, you'll have to right-click on the destination button and select the Foreground - drag n' drop doesn't work. Click OK after the color indicator on the Color To Alpha plug-in is changed to blue.
Step 4
There should now be a nice green and alpha image with no trace of the blue left. Next add the new background.
Step 5
Now create a New Layer (have Forground set to Red when you do this). Lower the newly created layer.
Final
Intention
Many times you have an image with a colored background, like the one above and you want to take out the background to use the image's subject in a composition. With gimp there are many ways to achieve this, one of which is using a plug-in specifically designed for this: Changing Background Color 1.
Step 1
In this tutorial I explore the select by color option to remove a particular color from the image. The first step, after you have loaded the image of course, is to click on the Select By Color tool.
Step 2
Like other selection tools, this one provides several options that can be modified. The top row of buttons sets the Selection Mode. We will use the add option, which means any color we click on will be added to the selection. You can also use the Shift key to acheive the same result. The other interesting setting is the Threshold. When you click on a color, the higher this setting is, the more similar colors to the one you clicked on will be selected. You can start by using the default setting and increasing it if you need to add more colors faster, or decrease it if you're selecting more then you want.
Step 3
Now it's time to start selecting the color you want to remove. Just start clicking on the color you don't want and watch the selection update. If that didn't select all the color you want, continue clicking on the unselected parts until you get the desired result.
Step 4
Finally, there is one last step before you can remove the background. You have to add an alpha channel (a common term for transparency in images) to your image. To do that you have to use the right button on the mouse to get the image menu and go to layers and add alpha channel.
Step 5
With the selection complete and with an alpha channel just choose from the image menu <Image> Edit -> Clear, and the image background will be gone.
Step 6
After the last step you should get something like this in Gimp. You can now use this image in a composition or in a web page with a different background like below:
Final
Of course you still have to take care of the details if you want to merge an image perfectly into another. The sunflower image was taken by the photographer Raymond Lofthouuse.
COLORING A BW SKETCH
Text and images Copyright (C) 2002 Marco (LM) Lamberto and may not be used without permission of the author.
Intention
First of all you have to acquire through a scanner or something similar your sketch. It doesn't necessitate to be truly a black and white image (2 colors), often a well contrasted grayscale image is better (use contrast autosketch or/and the brightness-contrast tools).
Step 1
Create a new image of the wanted size and place below the sketch layer a pure white background layer. Now turn the mode for the sketch layer into multiply. From now the sketch layer will stay forever over the others.
Step 2
Now let's start playing with colours! Create a new layer and call it "Details". In this example I've used it for painting the blue doughnut. As you can see, thanks to the multiply mode, the black lines of the sketch are kept while the white zones are "transparent". Don't be too afraid of going outside the shapes, in the next steps we will see that some stuff will "disappear", covered by other layers.
Step 3
Create a "Skin" layer over the "Details" one. Here I've coloured the skin and the shoes with the paint tool and the airbrush. For first you should fill with the base colour the shapes (use a paint tool), then apply (with the airbrush) darker shades on the edges and brighter ones over the cheeks.
Step 4
The "Details#2" layer is used for some extra details like the white text over the blue doughnut. I've used it because I want be able to change and retouch the doughnut shading without the white text (that should stay as brighter as possible).
Step 5
The "Hairs" layer contains ... well, what do you think will contain a layer called "Hairs"? Yeah, right answer! ;P Please notice only that this layer is below the sketch one but over the others, so the extra painted zones of the "Skin" layer are covered by this one. I.e. you can add some shadows over the forehead by painting over these zones.
Final
Finally I've added a "Shadows" layer for making the doughnut and the other elements less flat. This is the end. Still reading here? Now it's your turn! Quickly open GIMP and start playing! ;) The original tutorial can be found here.
Intention
This tutorial is aimed squarely at the novice GIMP user. The more experienced user may find some techniques here useful. This is the same procedure I used to create the logo on my homepage, albeit with slightly different settings. I'll point out the differences as I go along. I've taken a lot of screen shots to support this tutorial, so enjoy :)
Step 1
Fire up GIMP and create a new image. I used a white background at 500px by 200px. I feel this size it adequate as my website at the time of writing uses 500px tables.
Step 2
Start by laying down some text that is wider than 400px and not too thin. I've used a font called Pricedown. The text should be created as a new layer. If you use GIMP FreeType then it is done for you, otherwise click the New Layer button in the Layers, Channels, & Paths dialog (looks like a blank piece of paper). It will help to change the layer size to that of the image. Do so by accessing the Layers menu (right click or Control+Click on the layer you wish to operate on) and select Layer to Imagesize.
Step 3
Duplicate the text layer (text) twice. One for the highlight effect (highlight) and one for the shaded part of the effect (lowlight). The highlight layer needs to be white, so select that layer, check the Keep Trans. box on the Layers, Channels, & Paths dialog, and fill it with white. You can do this easily by dragging the white color swatch from the toolbox over to the image (assuming that the highlight layer is currently selected). Keep Trans. means "Keep Transparency"; this will ensure that any transformations or fills made to that layer will only affect the non-transparent part of the image.
Step 4
Duplicate the text layer again and move it to the top of the Layers stack (use the little up facing arrow head on the Layers, Channels, & Paths dialog). Make sure that Keep Trans. is un-
checked and then blur it. I used Gaussian Blur (RLE) at 10 pixels. When I did the original logo, it was set lower than this to make the effect less rounded. You will need to make sure that the layer boundary is larger than the layer so that the blur can spread nicely. Step 2 mentions this.
Step 5
Duplicate the blurred layer once (tmp1 and tmp2). These layers are used to create the edge lighting for the text.
Step 6
Nudge one of the blurred layers (tmp1) down and to the right about 5 pixels. The precise number of pixels depends on how blurred and thus how round the text will appear to be, so use your best judgement. You can nudge layers my using the Move tool and the cursor keys on your keyboard. It doesn't matter which of the blurred layers you use in this step, as long as you know which one you didn't move \x{2013} you'll be needing to do a very similar thing to that one soon.
Step 7
Now create a selection using the blurred layer (the one you moved in step 6) using Alpha to Selection. This selection is a precise selection based on the layer and includes alpha (transparency) information. Handy stuff. You'll notice that I've turned off the layer below (the
other blurred layer). This was done to make sure I could see how far I moved this layer during step 6.
Step 8
Step 9
Step 10
Cut (edit/cut or CTRL+X on PC or Command+X on Mac). This will remove the blurred layers selection from the highlight layer. You could do this with channel masks, but I'm a man of simple needs and wants. There's another step after this that I haven't documented, but that's because it's the same thing again (steps 6-10) but with the other layer (tmp2: see steps 5 and 6). Move (nudge) that layer in the opposite direction (up and to the left about 5 pixels), then make the cut from the lowlight layer. Once you're done, delete the two blurred layers (tmp1 and tmp2).
Step 11
I like to take quasi-breaks while doing some images, and this is one of those times. A good time to roll a cigarette or grab a cup coffee. I also tend to clean up temporary layers occasionally.
Step 12
Now we'll add the first elements of 3D-ness to the logo. The original text layer is the base layer for any color you want to add. I'll use grey70, but you could just as easily use any old color you like. It's a good idea to play with this as you can get some funky plastic logos too. Make sure Keep Trans. is checked when you fill the layer.
Step 13
Step 14
Click the blank piece of paper on the Layers, Channels, & Paths dialog and make a new transparent layer called outline. Move this new layer down the layers stack until it's underneath the original text layer.
Step 15
Select the original text layer (the one you added some color to) and do the Alpha to Selection trick again. Right click on the image and use <Image> Select -> Grow. This will make the new selection larger by a number of pixels - I used a value of 2 pixels. Once you have a selection, be sure to reselect the new layer (outline) so that you can fill it (step 17). And below is what it looks like.
Step 16
Step 17
Fill the layer with black and deselect (CTRL+SHIFT+A on PC or Command+SHIFT+A on Mac). As you can see, the image now has more background contrast. Now, duplicate that layer and lower the copy below the original outline layer. Make sure that Keep Trans. is not checked, and blur it. I like soft shadows, so I used a Gaussian Blur (RLE) of about 30 pixels. Drop the Opacity of the layer down to about 50 and nudge it to the right and down until it looks okay. A nice way to fill selection areas or layers that have Keep Trans. selected, is to simply drag the color from the toolbox color swatch to the layer.
Step 18
This is what the Layers, Channels, & Paths dialog should look like.
Step 19
I've duplicated the highlight and lowlight layers and made them all blend with the lower layers using the Overlay mode. This helps to make the edges more 3D.
Step 20
Create a new transparent layer called rust and select the bezier tool (shown here as the depressed button).
Step 21
Rust isn't uniform and I've decided to only worry about the lower half of the letters. Use the bezier tool on the new rust layer to start a selection that looks like...
Step 22
This. Click inside the bezier path once you close it (close it by clicking one the first node). This will create a selection. Use <Image> Select -> Feather to feather (blur) the selection. I used a value of about 10 pixels.
Step 23
Pick a nice bright orange or brown color for the rust. My site logo used a reddy-borwn color, but here I've chosen a bright orange. Fill the selection with it. Using the famed Alpha to Selection move, get the selection for the original text layer. Once you have that selection area, click the rust layer to make it active. Invert the selection (CTRL+I or Command+I) and Cut. This will leave only the part of the rust layer that actually covers the letters and not the extra.
Step 24
Step 25
The image should now look a little like this. Don't worry, it'll look better soon.
Step 26
Step 27
Making sure that you reset the color swatches on the toolbox, use the gradient tool to make a gradient in the Layer Mask so it looks like this.
Step 28
Final
With a little playing around you can get to this. I duplicated the rust layer and moved them (the original rust and the copy) down the stack until the highlight and lowlight layers were above them. I also duplicated the original text layer, switched on Keep Trans., and used <Image> Render -> Clouds -> Solid Noise to add a bit of interest to the layer. Try using the Curves tool to help with this. You may also notice that the outline layer is blurred. Sometimes this can help. The idea is, try stuff and find out. Well, thats it. Hope that taught you the power of selections and layer modes to some degree. There are many people who tout the use of channel masks, but don't under estimate the power of selections to do your dirty work.
TILABLE TEXTURES
Text and images Copyright (C) 2002 Adrian Likins and may not be used without permission of the author.
Intention
The GIMP 1.2 series have a nice new feature I refer to as gradient brushes. Essentially, this is just the regular paint tool, but instead of painting with a constant color, it gets its color from a gradient and rotates through the gradient as you paint.
Gradient brushes can be accessed from the standard paintbrush dialog. Just check the option "Use Color from Gradient" and start painting. You can also press the Gradient button to change the current gradient. Try "German flag smooth", for instance.
Just filling in an image with a gradient brush is a good start for interesting textures, and you can make some nice ones that way. But that gets a little boring after a while. To really spice thigns up a bit, you need some more interesting brushes. So called "grunge brushes" work quite well for this use. A very nice set can be found in the June 1999 edition of thegimp.com, in the brushes section. Get these for real fun with gradient brushes. Basically, just select one of those brushes, and se the spacing to something reasonable (most default to 10 or so). I would suggest setting the spacing to about 80-120 or so. Of course, please experiment. For example, lets choose the "Grunge 15" brush. Set its spacing to about 70 or so. Now choose a gradient from the the gradient selector (<Image> Dialogs -> Gradients). Just about any of them will do fine. Pick one at random, you can get nice results from any of them. For this particular example, I used "Caribbean_Blues". Now for the easy part. Draw random stuff on the image. Or not random. It doesnt really matter. If you want to stick to a very set pattern, your texture might look a bit more orderly. Fill the image completely if you dont want alpha poking though. Nice eh?
The hard part is making the image tilable. The easiest way to do this is to offset your image by half its height, and half its width. Select <Image> Layer -> Transform -> Offset. Then choose the convient "x/2, y/2" option, and hit OK. Your image will now show what used to be at its edges at the center of the image. The secret to making tileable images is to make this transition smooth.
For gradient painting with grunge brushes, this typicaly just means painting along those lines. You probabaly want to give it a bit of character so it looks more natural. You will probabaly want to avoid painting at the edges of the image when you do this. But if you do, just repeat the above steps again and you should be fine.
Offset that image one more time (or not,actually...), and your ready to go.
Things to tweak
Of course changing the gradient type, and the brush will have a big effect on the look of the texture, but so will more subtle things like the opacity of the brush, and the paint mode can make for some interesting effects. These type of textures also seem to work well for layering two or three textures together with different layer modes. All in all, this is nice and simple, and fast way to create some colorful textures.
Examples
Just some examples whipped up in a few minutes. The original tutorial can be found here.
SIMPLE ANIMATIONS
Text and images Copyright (C) 2002 Jakub Steiner and may not be used without permission of the author.
Intention
In this tutorial, you'll learn how to use GIMP's layers in a different manner. Unlike it's default composite function, using GIMP as an animation package requires you to think of every layer as of an animation frame. We'll discuss the two different frame disposal methods later on. For now let us think about every layer as of a separate frame.
Step 1
We'll create a very simple web banner. Let's start with a new image 468x60 px. Use white as the background color. Create new transparent layer. Select the whole image with Ctrl+A and fill it with black (Ctrl+,). Shrink the selection by 1 px (<Image> Selection -> shrink) and delete the selection with Ctrl+K. We created a 1 px frame around out banner. Now it's time to put our logo or the main theme picture into the banner. I have prepared a masked-out flower you see on the picture on the left. I just pasted the flower below the border frame, used alpha to selection, created an empty layer below it and filled the selection with black using Ctrl+,. After that I blurred the shadow using Gaussian blur RLE and offset it by 2px to bottom right. I couldn't resist adding the interlace effect using <Image> Filters -> Render -> Grid and a layer mask. In that layer mask i applied a b/w gradient, so that the left of the flower is not interlaced. This part of the tutorial is not the key element, so feel free to experiment. Once you're ready flatten the image using the <Image> Image -> Flatten Image.
Step 2
Now we're ready for the actual animation work. We will be creating a banner consisting of, say three lines of text being animated. Each frame will consist of the flower image and accompanied by some text. I don't want to make this boring, so lets make it three frames. The
first step will naturally be to copy our flattened image two times using the duplicate layer button in the layers window. Then we'll use the standard text tool to put a small text note on every frame. After typing the text onto the frame, GIMP will create a floating selection, that you need to position right using the move tool and anchor using Ctrl+H. The positioning might be crucial for the final animation, so you can use the following trick to make the positioning a piece of cake. Before using the text tool, set the layer (frame) transparency to a lower value, so you could see the layer below it. That way you can position the newly created text acording to the text below (on the previous frame).
Step 3
In every GIF animation you are allowed to specify the delay between frames. That way you can create a 12 second animation using only a few frames, because the delay does not have to be constant. In GIMP you specify the delay as a layer comment. Just double-click the layer comment in the layers' window and a delay in ms enclosed in brackets (). To check if the timing is good, you can preview the animation using the <Image> Filters -> Animation -> Animation Playback. You can even drag the preview around your desktop.
Step 4
In the last step, we'll use a very handy function for applying a filter to multiple layers. This function is provided by GAP, the GIMP Animation Package. Please go to the "Using GAP" tutorial to learn more about the tool. Before we can apply this effect, we need to create a new image out of the third frame. This is as simple as dragging the layer preview from the layers window to the toolbar. Now duplicate the image four times. With a rectangular select tool, draw a selction around the text. Now we're ready to apply a gaussian blur filter on every layer using varying parameters. Use the
<Image> Filters -> Filter All Layers function and select plug-in-gauss-rle2 from the list and press the apply varying button. The blur dialog pops up. Now we need to specify parameters for the lowest layer in the stack, ie. our first frame. We want to blur the text away in time, so for the first frame, let's specify a lower value. We'll blur in horizontal direction only, so let's make it v:0 h:2. After you click OK another dialog shows up. Here, choose continue and specify parameters for the last frame. We'll go for 20 px horizontal blur. You can backup the progress, but for now we will make the filter apply on all layers inbetween by clicking on continue in the next dialog. All we need to do now is to drag the layers back to the original image.
Step 5
Now we only need to save our animation as GIF. Before we do that, let's optimize the animation using the <Image> Filters -> Animation -> Animation Optimize function. This will create a new image using a different mode than what we have now. You can use two different modes for every frame of your animation. You can either use the replace mode (default), which will replace the old frame with the new one. It's like taking the frame out before adding a new one. The other is the combine method, in which the new frame is added to the previous frame. That way only changes need to be updated. That's what animation optimize basically does. The file size gets tremendously smaller. Now we need to index the image using <Image>Image-> Mode -> Indexed function (Alt+I). Try to use as little colors as possible and avoid dithering. Both number of colors and dithering tend to enlarge the filesize dramaticaly. I used no color dithering and generated 32 color pallette. The file size of the banner is about 7kB. If you now save the image as GIF, GIMP will ask whether it should save the image as an animation, which is exactly what we need. In the save as GIF dialog, you can specify the default delay (in our example it will be used for the blured frames) and disposal method. You can use your WWW browser to check the animation, or you can use the animation playback function in the animation section of the image menu.
Intention
Along with the brushes already included, you can create custom brushes using three methods. Simple shapes are created using th button labelled New at the bottom of the brush selection dialog. Complex black and white brushes can be created by saving a grayscale image as using the .gbr file extension. The content of such a brush is treated line an alpha-channel. This means that any pixel that is pure white is treated as transparent. However, in this tutoria we will be creating brushes that use pictures with colour and this brush will also have multiple images.
Step 1
Create a new image the size of the brush you will be creating. For our example, we will be creating a 64x64 image. Create it with a transparent background.
Step 2
Go to the Layers dialog and create additional layers with the fill type Transparent (if necessary, delete or clear the background layer if you forgot to make it transparent when creating the image). Give them any name you want. We will be just naming them Layer1, Layer2, and Layer3. The layer name really don't matter in this case.
Step 3
Draw the images you want in the layers that were already created. In our case we will be drawing a picture of a happy face in 3 colours (red, green and yellow). At the end your layers
should look something like this (see image above). You can save a copy of your image in .xcf format now, in case you want to edit it later.
Step 4
The last step is to save your brush as a GIMP picture brush. The extension of this kind of brush is .GIH. So right click on the image, then choose <Image> File -> Save As.... IF you want the GIMP to be able to use your new brush, you have to save it in the "brushes" folder inside your personal GIMP folder (for Linux and other UNIX systems, this is usually in "~/.gimp2.2/brushes/"). So select that folder and type in a name for the brush. For our example, the brush was named happy.gih The Save As Pixmap Brush Pipe dialog will ask you how you want to save the image. Since we have 3 layers make sure to put 3 in the Ranks edit box. You can also choose how you want the images to appear as you move the mouse aruond. In most cases Random will do fine. NOTE: The Spacing (Percent) means how much space is left before the next image is drawn. If the value is lower, then the image will be drawn more frequently. You can also adjust this value in the Brush dialog.
Final
To see our brush, go to the Brushes dialog and hit the Refresh button. Our happy image should appear in the dialog. If it doesn't, make sure you have saved the brush in the GIMP "brushes" folder and that it has an extension of .GIH. You will note that our little picture on the right has a little red triangle in the bottom right corner. This tells us that the brush contains multiple pictures. You can click on the brush image and hold the mouse button to see a preview of the brush. The brush animation will show you that it contains the three images. Let's test our brush. Select our brush from the brush dialog, create a simple image and start drawing.
IMAGE PIPES
Text and images Copyright (C) 2002 Adrian Likins and may not be used without permission of the author.
Intention
GIMP 1.2 introduced a lot of new features that have been further improved in version 2.0, including the ability to use full color "pixmap brushes". In addition, you can also combine single frame pixmap brushes into a "image pipe". A GIMP Image Pipe allows you to spray out series of full color pixmaps. To make it more flexible, the order the images are painted onto the canvas can depend on direction, angle, speed, or other factors. This effect can be used in many ways, from a simple way to paint repeated images, or as sophisticated texture generation. The flexibilty in the way images are sequenced and composited to the canvas on the image can make creating a image pipe to do what you want seem difficult. However, for almost all common image pipes it is easy to set them up.
Example 1
Taking a set of images and making a image pipe out of them is a common configuration. The easiest way to do this is to create each indivual image as a separate layer in an image, much like you would if you were going to save an animated image. And in fact this is often a convient way to think of image pipe creation. As designing an animation of which snapshots are going to be composited to the canvas. Let's start with a simple example image, an 8 layer image. In this case, with the numbers 1-8 on each layer. This will help to make it more obvious what the various "ranks" do. GIMP versions older than 2.0 could not reload gih files (GIMP image pipes), so I include the source xcf images here. The example image. To start creating a image pipe, you will need to save the file in the ".gih" extension. To use the brush immediately, you probabaly want to save it in the brushes/ subdir of your GIMP directory (probabaly ~/.gimp-2.4). To save the image you will be presented with a save dialog for the GIH plugin. (Image above)
For a simple image like this, the only values you usually need to change are "Spacing", The "Number of Cells", the number of "Ranks", and the "selection" for each rank. Spacing is pretty much the same as for regular brushes. It indicates what percentage of a brush width or height that the cursor moves between each time the shape is pasted. Ranks indicates how many levels of variation to use by the Selection values. For this image, the value of ranks should be equal to the number of images in the stack. Since it is possible to have multi-dimensional pipes, there needs to be a way to set more than one rank. For this example, we are going to choose to select from the rank using method "incremental". This essentially means that the images will be selected in the order they are in the layer stack. Other options include: Random: selects the images in a random order. Angular: selects the images based on the angle the brush is moving at. Velocity: selects the images based on the velocity the brush is moving at. Pressure: selects the images based on the pressure of the brush (requires a pressure sensitive tablet) xtilt: selects the images based on the xtilt (also requires a tablet) ytilt: selects the images based on the ytilt (also requires a tablet) After saving the image, you can "refresh" the brush list and then select the new image. For an example of what this can do, tale a look at the example image above (also making use of the fun gradient brushes).
Example 2
Tater Tots!
This pipe is a good example of making a image pipe out of a series of images. Each layer has a a bit of an image cut out and placed on a transparent background. Any areas that are transparent in the image will be transparent in the brush as well. To add a bit more of a "3D" effect, a slight drop shadow was added to each layer in the image. Save this image as gih with the parameters as indicated in the following screenshot.
Example 3
An example of a two dimensional pipe A interesting use for image pipes would be to simulate a natural media saturation. For example, maybe a brush that has ten different versions that correlate to tablet pressure. For this example, I'll use a somewhat contrived example for simplicity sake. It will use the "angular" parameter in for per layer dimension, and a "random" parameter to select which of the multiple images to use. I use this in a couple of brushes to "humanize" the output. Instead of having the same image stamped out over and over, it varies a little randomly.
The example source image is a 8 layer image, with each layer split in two with a guide. The guide isnt require but it makes it easier to create. A screenshot of the layers dialog showing creation of an image of this type.(Image above) You will want to save the image with the values show here:
Example 4
Using a image pipe as a way to generate textures.
Making tileable textures with gradient brushes is a tutorial on how to generate textures with just graident brushes. A lot of the same techniques that are used there can be used Image Pipes as well. The main advantage to using image pipes is that the brush as well as the color can change as you paint, which adds an extra dimension to the textures.
For this example, it is just another one brush per layer situation. The example source image is available. The image is saved with the paramaters as in image above. Example output:
Example 5
There are lots of "Image Tubes" created with and for Paint Shop Pro available on the internet. GIMP can load these files and save them as GIMP image pipes. Unfortunately, unless you really like pictures of teddy bears, puppy dogs, and unicorns, finding good PSP Tubes isnt so easy. There is a .tub loader plugin in GIMP that you can use to load .tub files you find on the net. Then you can turn around and save these files as a .gih file. We are going to start with a .tub file available from Hood's PSP Tubes, in this case the Fireball example. Hood's site is not available anymore but you may be able to find "HFireball.zip" or "H Fireball.tub" on several sites distributing PSP Tubes. The file needs to be loaded as a regular image, then saved as a gih image. Sometimes you may need to make some best guesses as to the save parameters. An example of what the image window will look like after initially loading the .tub file is shown above. Saving this file as a .gih file, and using the paramaters as shown in:
IMAGE PIPES 2
Text and images Copyright (C) 2002 Sam Jones and may not be used without permission of the author.
20 percent spacing Both the image pipe and the pixmap brushes are made as images in GIMP. A simple pixmap brush has one layer, and an image pipe has several. Both images need to be partly transparent, with alpha channels on all layers and no background. You save an image as type .gpb for a pixmap brush, .gih for an imagemap brush. GIMP searches $HOME/.gimp1.1/brushes/ for a user's customized brushes. When you save an image in either format, a dialog box comes up. For pixmap brushes, this dialog is simple. It asks you for a name for the brush and a default spacing. The name is simply the description that will appear in the brushes dialog when that brush is selected. The spacing determines how close together the images are.
A pixmap brush with 100% spacing will draw a bunch of pixmaps with touching borders. More spacing will have a gap between the pixmaps, less will mean the pixmaps will overlap. See the examples above.
The options for an image pipe are a bit more complicated. Let's take a simple image with four layers. The layers look like above. Click on the example above to download the GIMP file.
When I try to save this image as type "GIH", I get this dialog box: (Image above) There's a lot of options here. Here's a list of what the simple ones mean: Spacing: Same meaning as for pixmap brushes above. Description: Same meaning as for pixmap brushes above.
Cell Size: Gives width and height of the brush. Generally, you don't want to change these values. Number of Cells: Should match the number of layers in the image pipe. The last three fields are a little harder to describe. If you want to give this image a one dimensional image pipe, you put '1' under Dimension and 4 under Ranks. This gives you four images in your image pipe, one of which will be chosen each time the brush touches. The last field, Selection, is about how that brush is chosen.
Let's say we save the image above as an image pipe with one dimension, four ranks and random selection. One of the images will be chosen for the brush at random. If we paint a short line with it (spacing 150), we get something like image above.
If instead, we chose incremental selection, the layers will be chosen in order from the top layer to the bottom, which would look like this.
An angular pipe choses its layer based on the angle the brush moves. The top layer covers 0 degrees (straight up) and the angles to either side. The layers going down are assigned counter clockwise, evenly dividing the number of degrees with the layer. So with four layers, "A" will go up, "B" right, "C" down and "D" left, like this. Angular pipes can have more or less than four layers. If it was eight layers, they would cover, roughly, the eight compass points. Three layers would cover 120 degrees each, and so on.
There's a few more types of selection. One is 'velocity', and frankly I don't understand it. There's a few others that require a graphics tablet. If anyone gets me a graphics tablet, I promise I'll describe these selection options, too.
So, what can you do with a two, three or four dimensional image pipe? You can combine the selections. Take the gnome foot for example. You can cut one out and make eight layers. Four layers are for the left foot going in each direction, four layers are for the right foot going in each direction. You end up with a layer dialog that looks like image above. Click on image above to download the GIMP image Now, let's save this image with two dimensions. The first has angular selection and four ranks for that selection. That means these eight layers get divided up into four ranks of two layers. Then we select incremental selection with two ranks, which will divide each of those sets of two into sets of one.
So, what we have is feet which alternate left-right-left and follow the direction of the mouse. It looks a little like above.
Intention
Doesn't the title look really valuable? To reproduce this effect you need the incredible "Lighting"-Plugin, created by Tom Bech and Federico Mena Quintero. It is not in the standard gimp-1.0 distribution, you have to install it yourself. It can be found at <Image> Filters -> Light Effects -> Lighting Effects. This Plugin does a very good Bump-Mapping. Additionally it can map an enviroment-map to the image.
Part I
The trick is to use a good enviroment-map. I created it with <Image> Filters -> Render -> Solid Noise (X/Y-Size: 2.8, Detail: 1, Tileable). It is important for a good effect to get different grays in the top right corner. Then I did a <Image> Image -> Colors -> Auto-Stretch Contrast and a <Image> Filters -> Blur -> Gaussian Blur (IIR) with a radius of 5 to get the full range of gray. Then select the "Golden"-Gradient in <Image> Dialogs -> Gradient Editor... and <Image> Filters -> Colors -> Gradient Map it to the image.
The next step is to create a bumpmap for the text. Open a new grayscale image in the desired size, fill it black and paint the white text on it. To get a smooth transition do a Gaussian Blur on it.
Then open a new RGB-Image with exactly the same size and start the Lighting-Plugin. Select the "Enviroment-map"- and "Bumpmap"-Toggles and select the images in the appropriate notebook-pages. I prefer a lower value in the "Maximum height" Bumpmap option. I think 0.02 is good in most cases.
This is the result after a click on Apply. There is room for Improvements. Since the LightingPlugin doesn't support antialiasing yet it is a good idea to render the image in the double size and scale it down for the final image. Some other neat tricks can be found in the next part.
Part II
At the Bumpmap-Options you can select different between four different Curves for Bumpmapping. So you can select between a linear, spherical, logarithmic and a sinusoidial Bumpmap. There is a much more flexible way to specify the surface of the Bumpmap. The Key is the <Image> Image -> Colors -> Curves-Dialog. Create the text and blur it with a wider radius. Then select the Curves-Dialog and modify the text-profile. A little Blur (Radius 2) makes the Bumpmap a little bit smoother. See the examples above. Another possibility is the use of a different gradient.
Part III
To get Chrome-like effects try to use different enviroment-maps. Look at these examples. That's it :-) The original tutorial can be found here.
Intention
Meet Marius, my son. :) Before: After:
Then Gaussian Blur the top layer with an appropriate radius. You need to experiment to find good values, but roughly speaking one can say that the larger the radius, the wider the high pass filter's frequency response, and the "fatter" the lines in the final sketch. In this example I used 7 pixels, giving this result;
Now we have a low pass filtered version of our image; all gradients and no detail. Exactly the opposite of what we wanted. So, how do we obtain a high pass filtered version? Why, we subtract it from our original, of course. A good way to do that is to simply Invert the image, and blend it 50-50 with the original. First, Image->Colors->Invert;
Then, to blend the two, we adjust the Layer's Opacity slider to 50%, and our high pass filtered image appears;
Now it's time to Merge the two layers, so that we can continue to process them as one. Rightclick on the top layer and pick Merge Down. Now, back to the image. Was the effect a bit too subtle, perhaps? While not necessary, we can apply the Levels tool (Layer->Colors->Levels) to increase the contrast a bit, so that it's easier to inspect visually. In this example, I set Input Levels to 100-155;
That's pretty much it. I tend to want to hand-polish my images to get rid of various imperfections, though. Below is the result of softening the contrast on the lower right region, which is where the bright skin fell against the black background; The higher the contrast, the stronger the lines. I also fine-tuned the overall contrast (with Levels) to get rid of some of the noise in the face;
Finally I wanted to remove the annoying shadow below his chin and some of the specks scattered around his face, so I manually hand-brushed away parts of it, giving the final result;
PHOTO TO SKETCH
Text and images Copyright (C) 2002 Dave Neary and may not be used without permission of the author.
Intention
Tutorial on how to make a nice baby & daddy photo into a nice baby & daddy painting.
1. Original image
Straightforward Sobel edge detect (<Image> Filters -> Edge-Detect -> Sobel) of original (don't forget to save a copy of the original) The Sobel edge detect should be done on the background image (without an alpha channel) rather than a copy of the background (which has an alpha channel).
Bring out detail with an auto-equalise (<Image> Layer -> Colors -> Auto -> Auto-Equalize) of the sobel edge detect, and convert it to greys using desaturate (<Image> Layer -> Colors -> Desaturate).
We only want the strong edges, otherwise it'll look crap. To get them, we eliminate the edges with small magnitude. The easiest way to do this is with the curves tool (<Image> Image -> Colors -> Curves) like this. We set the curve type to free (which allows discontinuities), and then for the bottom 3/4 of the curve (or thereabouts) to 0. Just drag the mouse/pen along the bottom of the curves tool.
The result is much cleaner. The only problem is it's white-on-black, when we want black-ontransparent ideally.
Small trick to get to black-on-transparent. Invert the Sobel edge detect (you did keep a copy, right?) with <Image> Layer -> Colors -> Invert and apply our highpass-filtered copy as a mask. To do this, open the Layers & Channels dialog (if it's not open already), and add a layer mask to the layer with the inverted edge detect layer (<Image> Edit -> Copy with the highpass layer selected, <Layer> Add Layer Mask with the inverted edge layer selected, then select the mask and <Image> Edit -> Paste) Since we kept the strong edges in the highpass filtered layer, this means that we end up with a rather nice black-on-transparent layer.
This is the result of the trick above. It's shown here with a white layer behind it. We could stop here, and this is a decent sketch effect. For the colouring, we need some more work (mostly slogging, though).
images,original image & colouring layer in overlay mode We put our original image back in the background, and set the white layer to overlay (as we see here) - this means we can see the coloured areas behind the white layer - this is extremely helpful when we're painting the white layer, as sometimes the edges are rather fine, or are in the middle of an area that's more or less the same colour.
Using the colour-picker tool (looks like an eye-dropper), we select the colour we want to paint from the original image (just activate the "original image" layer and try to pick a colour representative of an area), and then we re-activate our colouring layer, which is still in overlay mode. Using a big brush (with the brush tool for more natural edges) we fill in the area of that colour roughly (doesn't have to be perfect). You should see the colour darkening as we draw with a colour similar to the background colour.
This is what we see if we set the colour drawing layer to normal mode. And we're on our way.
After some effort, all the regions get filled in. Final touches to make faces and the like look better for shadows and highlights were accomplished by selecting a representative shadow/highlight colour, and adding the extra bits with the airbrush tool (looks like an airbrush). After all our work, we end up with this very nice looking painting effect.
Intention
So, we want to create a nice paintbrush image with GIMP. This tutorial can be a bit complex and I think it is better for a bit more advanced GIMPer. If you want to learn the basics, a good way to do so is to get one of the many GIMP books written. If I must pick one to recommend, I think it would be Grokking The Gimp, it is pretty good. But I am sure many of the others are great too, check a few out at your bookstore!
Step 1
Step 2
We first create a new transparent layer, and name it "tip" since we start drawing the brush from the brush tip.
Step 3
Use the Bezier (Paths) tool to make a brush-shaped selection, like on the above image. This could be tricky if you are not used to the tool, so it might be helpful to check out my Bezier tool tutorials if you have trouble.
Step 4
Step 5
Make another bezier selection, now inside the black brush tip. Since a wet brush tip is rather shiny, we want to add a hilight too make it look realistic. Try to think where the light comes from, and make the selection accordingly.
Step 6
We are going to use the Blend tool (gradient fill) to make the hilight. You might want to make a new layer for the hilight so you can edit it later if you are not happy with the result. The important thing here is to set the blend mode to "FG to Transparent", we only want to add white, not the black.
Step 7
Make a blend from top to bottom, so that the white fades out towards the brush tip.
Step 8
Then make another bezier selection that will form the brush metal handle, this is a bit more tricky, try to think where the brush handle will point, and add small "roundings" to the ends. Then fill the selection with a rather mid gray gradient. It does not look very real yet, but we want to bring this to life next...
Step 9
Keep the selection active still, and start adding black shadows with the airbrush tool so the shape gets some depth and looks more three-dimensional. This takes a bit of work, start first with large fuzzy brush, and work towards finer detail by using a smaller fuzzy brush. As far as I know, real airbrush artists use the same method to paint, they just use masking film and tape in place of the bezier selection. Again, think how the light would reflect and how the shadows would be on a real object. And dont worry if it does not look right at first, it needs some practice and patience.
Step 10
Also add some hilights by using white color on the airbrush. You can make the object appear more metal-like by adding a second hilight to the "shadow" edge as if it was reflected from the background plane. If your background was having some color, you could add slight tint of that color to the "second" reflection. Again, since the metal has a pretty shiny surface, you can use the Dodge/Burn tool to make the shadows and hilights stronger. Using brighness and contrast might help too.
Step 11
We add the "engraving" by painting blackwith a very small brush, airbrush again works well. Try to make it look like some letter ornament or whatever you like.
Step 12
Add hilights with white color to the areas that would get reflection. Since the light comes from top left, the hilights go to bottom right of the black "engraved" shapes.
Step 13
Next we want to do the rest of the handle. We again create a new layer for it. Since it comes from "inside" the metal part, it is better to put it behind the metal part layers.
Step 14
Again, the bezier selection tool. Yes, I love it. You should too. Make a nice tapered shape that represents the brush handle.
Step 15
Doubleclick the "Bucket fill" tool and select "Pattern source" from the tool options window. Select one of the wooden patterns. This will make the texture of the handle. Fill the selection with the wooden pattern.
Step 16
Add another layer, this time for the hilight of the wood. Position it just above the handle layer.
Step 17
First, like you did on the "metal" part, shade the wooden handle a bit with the airbrush tool so it looks round. Then do a hilight like you did for the brush tip on steps 5-7. You might want to reduce the fill opacity a bit since the wood is quite not as shiny as the wet brush tip.
Step 18
Okay, it looks very much like a brush already... Lets just add a shadow and it looks better.
Step 19
Duplicate the image, delete the background and select "Merge visible layers" to make the brush just one layer. We are going to make this copy into a drop shadow for the original brush.
Step 20
Turn on "Keep Trans" checkbox on the layers dialog, and select the whole image and fill it black with the bucket fill tool.
Step 21
Unselect the "keep trans" and blur the layer a fair bit, I think I used something like 20 for the radius.
Step 22
Now scale the shadow image so that it is 60% of the original height, but keep the original width. You need to click the "chain" button on the scale dialog to change the image's aspect ratio.
Step 23
Copy the shadow image on the original brush image, and move it just above the background layer. The easiest way to copy a layer is to drag it from the layers dialog to an image.
Step 24
I wanted to erase some of the shadow of the handle so it looks more realistic. I just used the eraser tool with a big fuzzy brush.
Step 25
There! The finished paintbrush image. And you learned a lot about GIMP as well. Thank you for the interest :-) You can get the image I did for this tutorial in GIMP XCF format here. The original tutorial can be found here.
CREATING ICONS
Text and images Copyright (C) 2002 Jakub Steiner and may not be used without permission of the author.
Intention
Almost every desktop enviroment I've seen has a special application for creating icons, usually a very limited drawing application. In this short tutorial, we'll show you how GIMP (GNU Image Manipulation Program) can help you create icons for your desktop.
GIMP enables you to save compressed files and work with them transparently, using the .xcf format. However, since we're working with very small files, compression simply doesn't save enough space to justify the effort. Especially since filemanagers like Nautilus have problems with creating thumbnails for compressed images, it's best to accompany any .xcf files you produce with a .png version. (See Image above) Nautilus (gnome-vfs) can't yet handle compressed GIMP native files
You may think palettes are only necessary in special cases like indexing colors of web images. However, if you're going to create more than one icon, having a pre-selected palette can give your icons a more consistent look and feel.
You may want to consider using a palette that already exists. Many operating systems like MS Windows or MacOS have a system-wide color palette that is used on low color depth screens. You could also use one of the palettes that Tuomas Kuosmanen has included in his public palettes list. If you prefer to create your own palette, it's best to just define the most basic colors. That is, focus mostly on defining a set of hues you'll be using. Later on, you can tweak the value or saturation to create highlights or shadows of that particular color. Having a complex palette with many variations will make it complex and hard to navigate.
Getting Started
When you're ready to start, run GIMP by selecting Applications -> Graphics -> GIMP Image Editor from your menu panel, or typing gimp at the command line. If you haven't used GIMP before, the default window layout may be a little confusing. It's a lot like Photoshop and other similar applications, in that it uses a large number of dialogs. Select items from the File > Dialogs menu to choose which dialog windows you'd like to have open and which ones you'd like to have closed. For icon work, you may find it most convenient to use the main window, plus the palette and layers dialogs, and of course the actual image you're working on. To create a new image file, press Ctrl+N. Select a 48x48 pixel image, the standard Gnome icon size. Because working on such a tiny pixmap requires a lot of detail, zoom in to work on a pixel-by-pixel level. Try 8:1 magnification (<Image> View -> Zoom -> 8:1). At that magnification, however, you will begin to lose perspective. It's best to keep an additional window open with an unmagnified view, so you can see what your icon will look like. To do that, choose <Image> View -> New view from the image context menu (the little arrow in the upper left side of the window). Use a 1:1 zoom on this view, so that you can paint at an 8:1 zoom and see the results immediately. Make sure to turn off the selection decorations on the 1:1 window. To do that, focus the window and press Ctrl+T or choose <Image> View -> Toggle selection.
A Few Tricks
It seems at first that creating an icon is incredibly restrictive. After all, you have just a tiny grid where you will soon run out of pixels. However, there are a few tricks you can use to fool the human eye and make your icons look better. Basically, you'll be simulating or implying shape with color value and opacity.
Antialiasing
One of the basic aspects of bitmap images is the negative effect of Aliasing. Although many tools like the brush tool work well in large images, they aren't effective at the
icon size. In particular, drawing with a 1x1 pixel brush doesn't behave as well as could be hoped. The solution is to anti-alias manually. Some people prefer to work at a higher resolution, with full anti-aliasing, and then scale down, but the icon loses smoothness and most of the benefit of the larger size. In the end, it's necessary to touch up the image manually. In most cases, you're better off starting with just your 48x48 square and not scaling. As much as it sounds hard, manual anti-aliasing is easy, and even fun. All you need for this is the opacity setting of the pencil tool. Say we have an outline that's aliased (Like the image to the left). Select a 1x1 brush and set the opacity to something like 40%. When you start drawing with this black brush by clicking on the white surface, it will become light gray. One more click and it gets darker. That way you can easily create fluent transitions between the two border colors. You can also change the active color using Ctrl-leftMB or just by swapping forground and background colors (X). If you're using layers to have more freedom experimenting, you will find the erase tool as useful for anti-aliasing as the pencil (Right image). Make sure you turn on the hard edges option, for maximum precision.
Work Example
In this small tutorial, Ximian artist Jakub Steiner will demonstrate most of the techniques described in the section called "A Few Tricks" as he draws a TV icon.
Basic Shape
Normally, you'd use the bezier tool for shape editing, but a TV silhouette is simple enough that we'll just start with the rectangle selection tool. Create a separate foreground layer for the shape, and choose a light, but not completely white, color for the background layer. After you're done with the icon, you can drag colors from the palette to the background layer to make sure that the icon looks right on any background. Drag the black preview rectangle from the toolbox, or press Ctrl-+ to fill the silhouette. You should have a black square on a light background. Then, use the eraser tool to smooth the edges of the square so that the shape is better. This will also add a slight white shine to the corners of the image.
Making it Plastic
Next, we're going to use alpha blending of a selection to give a more three dimensional appearance to the silhouette. Select the TV silhouette by right-clicking on the layer in the layer window and choosing Alpha to Selection. Shrink the selection by 1 pixel and fill it with a linear gradient similar to the image above. Now you have a dark grey shape with a black outline, and slightly shiny corners.
Now it's time to add a bit more depth, using the highlight trick from the section called "Highlights And Shadows". Use a white 1x1 pencil to create highlights, and a black one to create shadows. By setting opacity of the brush to something like 20% you can get results similar to the image above.
Of course, a television isn't just a single square with an outline. You can create the screen exactly the same way you did the TV silhouette. Create a new layer, and add a smaller rectangular selection, positioned inside the television one. Fill it with black, shrink the selection by 1 pixel and finally fill it with linear gradient to form a screen like the one shown in image above.
An important aspect of glass surfaces is the reflection. To make the television screen look shiny and reflective, shrink the selection by another pixel and create a new layer. Now, pick the airbrush tool and a mid-sized fuzzy brush. Paint a white reflection like the one in image above. If you want to create horizontal monitor lines on the screen, you can use the interlace effect. To do so, create a new layer above the current one. Render white horizontal lines with <Image> Filters -> Render -> Pattern -> Grid. Make sure you set the layer mode to Overlay.
After that, you'll want to create buttons. This is relatively simple: just create a circular selection with the elipse tool and fill it with radial gradient (image above). Choosing a gradient instead of a solid fill provides a bit of shine to the button, so even if it's just a few pixels across, it looks distinct and three dimensional.
This time we'll use the bezier selection tool to create the outline of an object. With a small shape, it can sometimes be difficult to use the bezier tool, it's hard to create a small shape, because the nodes snap to the pixel grid, but it's worth the effort because it makes the shape look sharp, like the one above. You can look in the GIMP manual for more information about editing bezier paths and working with the bezier tool.
To create a shadow for the remote, copy the path window and moving just one node. The shadow in this image is done exactly this way.
You can make almost any image, especially a small one, easier to understand by adding black object outlines to enhance contrast. To do this, you'll use the opposite of technique you used to create the television silhouette with its outline. First, right-click on the remote control layer and select Layers -> Alpha to selection. Create a new empty layer below the remote control layer. Increase the size of the selection by 1 pixel, and fill the selection with black.
GIMP may not grow that selection perfectly, and you will probably have to alter the result manually. In this case, we'll use the erase tool with a 1x1 pixel brush, and opacity between 60 and 70 percent. Choose the "draw straight lines" option, and smooth the outline by drawing close to the border of the object.
Now, to make the object a little more realistic, we'll use our highlight trick. Use the pencil tool with a 1x1 pixel brush and opacity set quite low, near 20%. The result makes the object very real.
To create buttons on the remote control, use the same technique as you did to create the button on the TV: Make a selection with the bezeier tool, then fill it with a gradient, and apply highlights and shadows with the pencil tool as needed.
Adding Glow
For extra realism you can add a TV glow. Create a layer above the screen, but below the remote. Create a rectangular selection of the screen, then increase its size by 6 pixels and fill it with blue. Now, shrink that selection by 3 pixels and fill with white. Deselect the are with Ctrl-Shift-A and apply <Image> Filter -> Blur -> Gaussian Blur RLE by about 5 pixels. Now set the layer mode to overlay, creating the transparency effect.
USING GAP
Text and images Copyright (C) 2002 Jakub Steiner and may not be used without permission of the author.
Intention
GAP is an advanced tool to be able to create animations, this guide should give you some sort of view of how GAP works and what you can do with it. For a good tutorial of how to make an animation with GAP then take a look at the "Advanced Animation" tutorial.
Main Interface
Source Image/Layer specifies, which layer you want to animate on top of the current image. If you select a layer from a multilayer image, make sure you don't forget to specify the stepmode as well. The stepmode is there to define how you want to animate the multilayered image you specified in the source image drop down. Mode defines what mode should be GIMP using for the layer in the final layer stack. In the modifier section you specify placement, dimension and opacity values for the current key. You can navigate in time by adding time points as shows the timeline section. At the bootom of the dialog you'll find some inportant sliders. The duration of the animation is specified using the start frame and end frame sliders or input boxes. Preview frame renders frame # specified when the update preview button is pressed. Layerstack defines where the inserted objects will go in the layer stack of the final image. 0 means top of the layer stack, while lower values move the layer towards bottom of the image.
Stepmode
Stepmode defines how you want the source multi-layer image to be animated withing the final animation render. Loop will suprisingly loop all the layers/frames of the source animation endlessly, while loop reverse will do the same, but for the opposite direction. Once is a simple one-time loop of the source animation, once reverse does it in the opposite direction. Pingpong will create a looping animation, but once it reaches the bottom of the source image stack, it moves the opposite direction. Use the last mode (none) if you only want to use a single layer out of a multi-layered source image. The animation will start from the specified layer, so make sure you don't miss out some frames. If a source image is a one-layered one, stepmode will not have any effect on the result whatsoever.
If you want the final rendered layer to be different mode than the default normal specify it in the mode popup. The handle option is used for exact placement of the source object into the final image. Select whatever option you wish to use to place the object in respect to the crosshair on the image preview (and it's x and y coordinates). In the middle section of the dialog, you can define placement and dimensions of the rendered object. You can also set opacity and rotation of the object. You do this for every animation point (see later on). Gimp will compute the values between those points. Every animation should at least have two animation points. For every animation point you define values for position, rotation, scale and opacity. In the animation point section you can add points and move within those to set the mentioned attributes for a particular point. Every animation point is shown on the image preview acording to his x,y position.
At the bottom of the dialog, you can specify the segment on the animation to render the current source image animation to. The preview frame slider is used in conjuction with the update preview button. You can use it to get the backroung image from a particular frame of the animation to be able to position the source object precisely. It will not have any effect on the final rendering. Layerstack is used to place the source image into a particular position in the final rendering layer stack. 0 means top of the stack (covering everything below it, also depending on the mode). Force visibility vill toggle all layers in the source image to visible, so that the final rendering does not have "holes" in it. Clip to frame will crop anything thats outside of the image dimensions. It will reduce file size, but you'll be unable to move the object on the final rendering to alter the animation.
Intention
Welcome to the advanced GIMP animation tutorial. Here you'll learn how to use the GAP, GIMP animation package. It is very advanced, but the user interface might be confusing for some at first. That's why we'll start with a little theory before we move over to the practical part. The key function of the GAP is the move path dialog. Please go to the "Using GAP" tutorial to learn more about the tool.
Step 1
To make things easier, we'll start with a ready-to-go static image. To load it into GIMP, just drag the image above to the GIMP toolbox. In case this doesn't work for you, copy the link by selecting Copy Target or Copy Link Location from the image context menu accessible by right-clicking on the image. In GIMP, choose Open Location from the toolbox File menu and paste the URL there. Gimp will download the compressed image and open it for you.
Step 2
Now drag the background layer from the static image to the GIMP toolbar. This will create a new white image we'll use as a base for our animation. To be able to work with GAP you need to save it in GIMP's native format, .xcf. Create a separate directory for the file, it will fill with many frame files soon. The file needs to be named like this: name-0001.xcf You can only change the name part. The rest needs to be exactly the way shown. GAP works on series of .xcf images, so that you can work with layers the same way as you do in static images. You don't have to copy the file yourself to add a frame. GAP has series of functions to help you manage frames. We'll create a 20 frame animation, so the first thing will be to copy the first frame 19 times using the video/duplicate frames function.
Step 3
Now it's time to use the move path function. Make sure you have the static image open but use the function on the white background image. In the dialog, select the logo image as source and make sure you set the stepmode to none! Keep the mode as normal and choose some handle mode. I have used center, so use that if you're going to stick with the parameters provided here. For the logo we'll animate two parameters. First, we'll zoom out the logo so it appears to fly away from the observer and combine that with opacity increase. For the first animation point use the following parameters: x:157, y:74, width:800, height:800, opacity:20. Keep the rest default. Now add a new animation point by clicking on the add point button. Notice how the status above the button changed to current key: [ 2 of 2 ]. Now change the width, height and opacity back to 100%. You can check the result on any animation point by navigating to it (using next and previous or other buttons) and clicking on the update preview button. You can also preview the whole animation using the Anim preview button. This will create a new layered image, so don't be impatient, it takes a while.
Adding points to your animation creates linear time segments between those. If you want to create non-linear animation, just set a specific frame to the active point using the keyframe slider. We won't need it for the logo animation, so let's just press ok for now.
Step 4
Now we have a rendered sequence of images. You can navigate them easily using the video/VCR navigator. Pressing play on the navigator will call two functions, frames to image and animation playback, so it's fast and convenient to use it to check the looks of your animation. You can also specify the default delay between frames by setting the framerate in FPS (frames per second). The higher the value, the smoother the animation will be, but more frames will be needed. You can also render only segments of the whole animation by selecting particular frame thumbnails in the navigator before pressing the play button. Use shift, ctrl or drag your mouse to select multiple frames. If you press Shift while pressing the play button, the resulting animation-image will be optimised (as discussed in the simple animation tutorial). As you can see on the image above, I have added some more movement effects for every source layer of the static image using only the move path dialog. You can now try to recreate the animation yourself, you know tool to be able to.
Step 5
All we need to do now is to save the animation. You can choose to go for the GIF format as I did with the image above, but the filesize is too huge to be widely accepted on the web anyway, so you can consider using a regular animation format like avi (needs special version of the xanim player from Loki) or mpeg1 / 2. To save the animation as gif, first apply the video/frames to image function. This will create a single multi-layered image with the specified delay. Now apply the animation optimize filter
(not that useful in this case) and finaly index the image to 16 color without using any color dithering. The file will still be about 170kB, so it's huge. You can consider trying some specialised optimisation software like GIFsicle. Maybe MNG with its sprite based animation will make it more suitable for the web. Rendering will happen on the browser side and I'm very excited about the idea. Last thing I can't help myslef not to mention is to thank Wolfgang Hofer for making such a great plugin that takes GIMP functionality to a new level. With GIMP 2 rendering engine we'll probably see more "applications" like that using GIMP's features to provide us with another area of application. I'd also like to thank the GIMP developer community to work hard every day to give us the best web gfx tool there is. If you just started to experience GIMP, don't hesitate and drop by up at #gimp on irc.gimp.org:6669.
Intention
In this tutorial I'll show you some different ways to convert color RGB images to B&W: the "standard" grayscale conversion operation. the desaturate operation. decomposing to RGB and using any one of the channels. decomposing to HSV and using the Value (V) channel. decomposing to LAB and using the Lightness (L) channel. using the Channel Mixer filter. We'll examine each of these in turn.
The Procedure
Here is an example image, loaded into GIMP. I thought it might look nice as a black and white image.
Via Grayscale
Here is what I get if I use the standard mode change to grayscale from RGB. Duplicate the original image (Ctrl+D) and right-click on the copy. Select <Image> Image -> Mode -> Grayscale. I don't know how this conversion works in GIMP, but I have read that Photoshop uses a standard mix of the RGB channels for their grayscale conversion: RED=30%, GREEN=59% and BLUE=11%. Supposedly this mix accounts for the eye's sensitivity to different colors. This formula does a pretty nice job in the general case, but some images do not work as well with it, particularly if the green channel component is not strong.
I suspect GIMP uses a similar formula. My experiments with the Channel Mixer (more on this below) support this.
Via Desaturate
Here is what I get if I use desaturate instead. Duplicate the original image (Ctrl+D) and rightclick on the copy. Select <Image> Image -> Colors -> Desaturate. Unlike the grayscale mode
change above, the channels are not remixed in different percentages, so we should expect different results. The result is visually different; note the increased contrast in the scales. Also, compare the 100% zoom views at right and in the previous grayscale example. You can see a lot more noise in the desaturated zoomed view (examine the blurred area below the spikes). The reason is that we are getting more blue and red channel noise, whereas in the grayscale mode change operation the algorithm is giving us a remix of 60% of the clean, detailed green channel.
A third method is to consider the red/green/blue channels of the image. Each one can be represented as an independent grayscale image. Right-click on the original image and select <Image> Image -> Mode -> Decompose. Select the RGB option and click OK. Here you can see the three channels: red (top), green (middle) and blue (bottom). You can see that the red channel contains most of the luminance information as well as a lot of noise, the green channel has the least noise, and the blue channel has shadows and noise. Often the blue channel has the most noise, but not in this case.
Very often the green channel contains an excellent B&W version of the image. If nothing else, taking a look at the RGB decomposition is important to give you an idea of where the important information is in your image, and where the noise is.
Another possibility is to decompose to Hue/Saturation/Value components and consider the Value image (the other two are not usually useful for this purpose). Right-click on the original image and select <Image> Image -> Mode -> Decompose. Select the HSV option and click OK.
Yet another decompose option: LAB mode. Right-click on the original image and select Image/Mode/Decompose. Select the LAB option and click OK. The Lightness component is a very interesting one because it contains all of the luninance information (whereas in RGB and HSV some of that information is spread into other components). You can very often see an expanded tonal range and discover hidden detail in the shadows by examining this component. Not often useful by itself, but it can be combined with other layers for interesting results (see Tips at end of article). Note: the LAB decompose option was not distributed with the version of GIMP I got (ver 1.2.3). I don't know whether it comes bundled with newer versions. I downloaded it from the GIMP Plug-in Registry and compiled it myself.
Just for fun I tried decomposing into CMYK. The Black channel is interesting: it resembles a negative.
The final technique is the Channel Mixer filter. Right-click on the original image and select <Image> Filters -> Color -> Channel Mixer. You'll get a dialog box like the one at right. Click the checkbox that says Monochrome. Make sure the preview checkbox is also checked. Now play around with the levels of the three channels, seeing the results in the preview window. If you don't want to change the overall brightness of the image then the three
values should add up to 100%, but feel free to experiment (checking the "Preserve Luminosity" box will also preserve the overall brightness of the image--see the Tips section below for more explanation of this option). Dialing in Red=30%, Green=59%, Blue=11% ought to give you something that looks nearly identical to what you would get with a mode change to grayscale. When you have something that looks decent in the preview, click OK. If you don't like the look of the result, Undo (Ctrl+Z) and reapply the filter with different settings (Shift+Alt+F). The advantage of the channel mixer is (obviously) flexibility. I like to decompose and examine the individual RGB channels, as we did earlier. That way I can see what is good and bad about each, and then use the channel mixer to combine them accordingly. In this example, I could see that the green channel did not really have much to offer, and had the least contrast in the iguana's scales; still, I mixed in 30% to help with the noise. I liked the blue channel for the great contrast it adds to the scales. Red's got a lot of noise, but I mixed in just enough to use some of the contrast and luminance information. You can see from the close up that it isn't quite as good the grayscale version in terms of noise, but the noise isn't too bad, and the trade-off is a lot more contrast and interest in the overall tonalities of the image. Note: the channel mixer plug-in was not distributed with the version of GIMP I got (ver 1.2.3). I don't know whether it comes bundled with newer versions. I downloaded it from the GIMP Plug-in Registry and compiled it myself.
Tips
Once you have a good B&W version of your image you may be interested in adding some simulated film grain. If you are wondering what the "Preserve Luminosity" option does in the Channel Mixer, I have the answer. I was curious myself, and asked the author of the Channel Mixer, Martin Guldahl, about it. This was his reply:
Hi Eric:
The 'Preserve Luminosity' option just maintains the luminosity at the same level regardless of the slider values.
For example, suppose the sliders were are Red:75%, Green:75%, Blue:0%. With 'Monochrome' on and the 'Preserve Luminosity' option off, the resulting picture would be at 75%+75%+0% =150%, very bright indeed. A pixel with a value of, say, R,G,B=127,100,80 would map to 127*0.75+100*0.75+80*8=170 for each channel. With the 'Preserve Luminosity' option on, the sliders will be scaled so they always add up to 100%. In this example, that scale value is 1/(75%+75%+0%) or 0.667. So the pixel values would be about 113. The 'Preserve Luminosity' option just assures that the scale values from the sliders always adds up to 100%. Of course, strange things happen when any of the sliders have large negative values.
Other Examples
Left image: The original image. Right image: Converted using channel mixer (80% green, 20% red).
Left image: The original image. Right image: Converted using channel mixer.
SELECTIVE COLORIZATION
Text and images Copyright (C) 2002 Eric R. Jeschke and may not be used without permission of the author.
Intention
In this tutorial I will explain how to convert a color photograph to a B&W one with color restored to selective areas. With the right subject this can give really striking results, as you can see for yourself. This technique is elsewhere referred to sometimes as "hand coloring" :-) The basic technique is to duplicate the color photograph, convert the duplicate to B&W, and paste it as a new layer on top of the color image. Add an opaque layer mask and then selectively paint transparency into the upper mask, exposing the color photograph underneath. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a reader comment I saw in a "hand-coloring" tutorial on photo.net (great web site by the way, I recommend it).
The Procedure
Step 1
Duplicate the image (Ctrl+D). By whatever method suits you best, convert the duplicate image to B&W. Once you have
gotten the B&W version that you like, change it back to RGB mode (<Image> Image -> Mode > RGB). In this example, I tried the channel mixer, but ended up in this case preferring a simple conversion to grayscale (<Image> Image -> Mode -> Grayscale), then back to RGB.
Step 2
Open the Layers dialog (Ctrl+L). Make sure that the original color image is selected in the Image drop down box. Click on the new layer button at the bottom of the dialog. Here I've named the new layer "B&W" Make sure the new layer is selected in the layers dialog.
Step 3
Go to the B&W image and select all, then copy (Ctrl+A then Ctrl+C). Then go to the color image window and paste (Ctrl+V). The B&W image should be pasted into that layer, obscuring the color image. Click the anchor button in the Layers dialog to anchor the pasted image. You can close the B&W image window you just copied from now, if you want.
Step 4
In the Layers dialog, right-click on the B&W layer and select "Add Layer Mask". In the Add Mask Options dialog, select White (Full Opacity).
Step 5
Make sure that Black is selected as the foreground color in the toolbox. We're going to paint transparency into the layer mask to reveal the color image below. Bring up the Brushes dialog (<Image> Dialogs -> Brushes) and select a big brush. In the toolbox, select the paint tool ( in color. ). Begin painting the interior of the parts you want to be
Step 6
When you get to the edges of the colored part, zoom in to make life easier.
Step 7
At the very boundaries of the colored image I typically zoom in to 300% or so. Switch to a small, feathered brush and very carefully paint the edges. If you only paint a little at a time it makes it much easier to use GIMP's excellent undo feature if you accidentally stray outside the boundary. If for some reason you can't undo, don't worry: just switch to white paint and paint opacity back over your mistake to repair the mask.
Final Step
When your all done, go over the colored part carefully to see if there are any gray (opaque) specks that you missed. Then zoom out and have a look. Voila!
Tips
For this kind of fine paint work, a pen tablet like this Wacom one is very useful. For photo retouching you don't need any bigger than a 4x5 model. In this example I restored the original color from the color image, but there is no reason that you couldn't paint other colors onto the second layer. Just make sure that the image is selected and not the layer mask in the upper layer of the Layers dialog (click on either the image icon or the mask icon to select the one you want to work on).
Try blurring the lower color layer, or running one of the interesting "artistic" filters on it (pastels, oil painting, etc). You probably want to do this before you create the B&W copy.
Other Examples
Further Reading
a "hand-coloring" tutorial on photo.net The original tutorial (possibly with updated information) may be found here.
Intention
Images captured by a CCD or CMOS imaging chip will often have some noise present. This noise typically can be seen as RGB "flecks", especially noticable in the in the shadow areas of an image. The red and blue channels are especially susceptible. Higher ISO settings and higher ambient temperatures increase the likelihood of acquiring this noise along with your image. If you find it necessary to shoot with a higher ISO and you find that you have an unpleasant amount of noise in your image, this tutorial will help you improve the image.
The Procedure
One procedure that works reasonably well is to apply the Despeckle filter. Unfortunately, this filter will soften the image. Fortunately, you can get sharpen the image to partially offset this.
Step 1
Here is the original image. Notice how bad the noise is, especially in the shadows of the face and in the white wall (back right).
Step 2
Right-click in the image and select <Image> Filters -> Enhance -> Despeckle. You can play around with the settings, but you'll likely want to keep the radius pretty small. If you raise it too high you'll destroy details like the catchlights in the eye. The "Recursive" option seems to cause a more aggressive filter effect. Try it if you have an especially noisy image. Examine the resulting image, zooming in to examine shadow areas. You'll notice that the noise is appreciably less objectionable. You cannot really eliminate it, but it is "smoothed out". Unfortunately, you may also notice that the image is softer; the despeckle filter actually blurs the image. Fortunately we can offset this to some degree by sharpening.
Step 3
For best results, especially with a noisy image, you'll want to use smart sharpening, explained elsewhere on this site. This particular image was edge sharpened on all RGB channels. If you find edge ("smart") sharpening too difficult, just apply a little global sharpening to offset the softening.
Step 4
Zoomed out (upper left). Compare to the original (upper right) Look at the arm and the white wall in back right. Much better.
You can open the Layers dialog (Ctrl+L), click on the Channels tab and just select the channel(s) that you want to apply the filter to. To examine the individual channels for noise, right click in the image and select <Image> Image -> Mode -> Decompose; choose RGB for the decomposition. Similarly, you can try decomposing to HSV or LAB, running the despeckle filter on one or more parts (e.g. value channel from HSV) and recomposing. Note: along these lines I have seen it suggested from several sources that decomposing to LAB, applying a slight gaussian blur to the A+B channels and then sharpening the L channel is a good approach to reducing CCD artifacts. I have to say that so far in my experiments this approach has not worked for me; I find the despeckle method far superior.
Other Examples
Intention
Digital cameras often have quite some noise in their pictures. Some are worse than others, but it's there. Here I'll show you a way to get rid of that noise using the selective Gaussian blur filter. The basic idea behind selective Gaussian blur is that areas in the photo with contrast below a certain threshold gets blurred. You could think of it like the opposite of unsharpen mask (that sharpens everything with contrast above a certain threshold.
Step 1
Since the selective Gaussian blur filter doesn't have a preview and is quite heavy to compute (proportional with blur radius), it's easier to only work on a cropped version of you picture. Select the crop tool from the tool box, draw a selection and click "crop". For best results, this should a part where there's some noise you want to remove and some detail you want to preserve.
Step 2
The next thing is to experiment with different combinations of the settings ("blur radius" and "maximum delta") in the selective Gaussian blur filter. Normally I find that both settings should be between 5 and 10, where low numbers has less effect and higher numbers more, but this is very depending on the camera. In short, maximum delta should be just high enough for the filter to kick in on the noise and blur radius should be just high enough to remove it (actually blend it with neighboring areas).
For a more in depth explanation of what the settings do see http://www.ftgimp.com/help/C/filters/sel_gauss.html. After playing with the settings a bit I liked the clean look of a blur radius of 10 and maximum delta of 10. Then I checked what those settings looked like on another crop (which is always a good idea to do), I decided that it was on the very edge, and maybe even too much. There was too much loss of detail in the hair.
An option would have been to back off a bit and use settings around blur radius 7 and maximum delta 6, but then again the only offending area was the hair. I finally decided to go with settings of 8/7. You'll often find yourself in these arguments with yourself over when it's too much and when it's too little. All I can say is that you develop a feel for it, and I'm still not finished developing that feel. In any case, it's good to know that the first things that start to look funny are often faces and hair.
The result
After 8 minutes my AMD-K6 300 running Linux finished the process, and I got the following (note they are resized to 640x480 from 1280x960, you can get the larger files at the bottom of this page): First image: Before. Last image: After (blur radius:8, maximum delta:7).
Before:
After:
Intention
In this tutorial I'll show you how to do create a contrast mask for your image in GIMP. A contrast mask allows you to reduce overall contrast, simultaneously bringing out more detail in highlights and shadows. This may be necessary to obtain a decent print, because prints on paper do not have as much dynamic range as a monitor; if you don't control the contrast, detail in the highlights may blow out and detail in the shadows can block up and become muddy or even black. You can of course modify your image directly in GIMP to decrease contrast, but the advantage of the contrast mask technique is that it allows you much more precise control, and gives better results.
The basic technique is to create a layer above the image that contains a B&W negative of the image. The images are combined in overlay mode: dark parts with light, light parts with dark. All the while your original image remains blissfully unchanged on its layer. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a Photoshop tutorial on the luminous-landscape.com web site (great photography web site BTW; I recommend it). The contrast mask technique does some similar things for the exposure as the digital split ND filter and the blended exposures techniques. If you feel your image has exposure problems you might want to consider those techniques as well. Each one has different strengths. Occasionally this technique gives unacceptable color shifts in certain images. Sometimes it is just the ticket. Experiment to see if it can work for your particular image.
The Procedure
Here is the original example image, loaded into GIMP. The red leaves are a little too dark to make out the detail; if printed, the result would be pretty dark and muddy. At the same time, the yellow flowers have a couple of specular highlights that would probably blow out the detail if printed. We want to brighten the dark areas a little and darken the light areas a little. In other words, reduce contrast.
Step 1
Open the Layers dialog. Right-click on the Background layer and select Duplicate (there is also a button for this in the bottom button bar of the Layers dialog.
Step 2
Now double-click on the duplicate layer and rename the new layer "Contrast Mask". (This step is not strictly necessary, but it is helpful to prevent confusion about what is on each layer, especially if you add some additional layers for other editing purposes).
Step 3
Select the Contrast Mask layer. Go to the image window and right-click, selecting <Image> Image -> Colors -> Desaturate. The image should look B&W.
Step 4
Right-click and select <Image> Image -> Colors -> Invert. You now have a B&W negative image of your original. We're going to combine this with the original (light with dark, dark with light) to reduce the overall contrast.
Step 5
Go back to the Layers dialog and in the "Mode" drop-down box, select "Overlay". The result may look better in terms of contrast, but degraded in terms of overall sharpness. Don't worry, we're not done yet.
Step 6
Go back to the image window and right click, selecting <Image> Filters -> Blur -> Gaussian Blur. You will need to experiment to find the best value, but typically a value between 10 and 30 will do nicely. After blurring the contrast mask the overall image should now look much sharper. Click on the "eye" next to the Contrast Mask layer in the Layers dialog to rapidly compare the image with and without the mask. Similarly, turn off the Background layer if you want to view the mask to do further work on it.
The image at top left is the original, the top right is with the contrast mask.
Step 7
It is informative to see how this technique compares to the conventional technique of using the contrast dialog to adjust contrast. I've tried to adjust the contrast to have the leaves appear about the same. I think the image with the contrast mask has a lot more pop! This one looks kind of flat by comparison.
Step 8
To see why this is so, compare the histograms of the images. The top one is for the original image, the middle is for the image with the contrast mask, and the bottom one is for the original image with the conventional contrast adjustment. Note how the typical contrast adjustment has lost a lot of values at both ends, but the mask technique basically preserved the entire scale.
Step 9
You'll have to flatten the image if you are saving it to a typical image format like TIFF or JPEG (but not if you are saving to GIMP's native XCF format). To do that, right-click on the image and select <Image> Layers -> Flatten Image.
Fine Tuning
Now that your contrast mask is created, it's time to fine tune it. Here are some things you can do: Use the "Opacity" slider in the Layers dialog to decrease the effect of the contrast mask overall. Apply Levels or Curves to the contrast mask to open up the shadows or reduce the highlights further. Apply the dodge and burn tools to the contrast mask. Apply a layer mask to the contrast mask and use it to select only parts of the contrast mask; e.g. if you only want the contrast mask to apply to certain areas of the image (see my example of this below).
Tips
See this article for some informative tests on the effects of the Gaussian Blur step on the contrast mask.
Other Examples
With a contrast mask as described above. Notice how the sky has recovered some blue, and the detail visible under the tree!
Here's an example of how this technique overlaps with the digital split ND filter approach. Which do you prefer?
With a digital split ND filter. (left image) With a contrast mask as described above, plus a layer mask with a gradient fill, so the contrast mask is mostly applied to the area below the cliffs. (right image) Note particularly the change in the color of the cliffs and the light part of the sky just above the cliffs, in the image using the full contrast mask (upper right). This shows how a contrast mask affects all parts of the image, unless you selectively disable part of the mask, as I did in the lower right. Note also that with the split nd filter (lower left) I was able to brighten the
foreground more; I could apply a general levels tweak to the contrast mask to achieve the same thing, but it seems like more work. This illustrates a general point for me: the digital split ND filter technique is the easier approach when you're already satisfied with half of the image, whereas the contrast mask is a better starting point if the overall image needs contrast reduction on both the dark and light sides. The original tutorial (possibly with updated information) may be found here.
SEPIA TONING
Text and images Copyright (C) 2002 Eric R. Jeschke and may not be used without permission of the author.
Intention
In this tutorial I'll show you how to sepia tone a color or black and white image. This technique is modeled on the traditional darkroom method of sepia toning in that the sepia color is applied "unevenly" to areas of different tonality. It works much better than most of the simple methods I've seen for image editors and provides great control! The basic technique is to create a "Sepia Mask" that will apply a sepia color layer according to a layer mask that is based on the tonality of the image. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a Photoshop tutorial on the RetouchPRO web site.
The Procedure
Here is the original image, loaded into GIMP. It has a bit of an old-time look, so I thought it might work well as a sepia-toned image.
Step 1
You can compare the result we will get below to GIMP's built-in Script-Fu for sepia toning (<Image> Script-Fu -> Decor -> Old Photo) as shown at right. Come back and compare to this when you get to the end of the tutorial.
Step 2
Duplicate the original image (<Image> Image -> Duplicate or Ctrl+D). You may want to minimize the original now (or close it) so you don't choose it by mistake. Using whatever technique you like best, convert the duplicate to B&W. I recommend the channel mixer for best results, but you can also convert to grayscale (<Image> Image -> Mode -> Grayscale) or desaturate (<Image> Image -> Colors -> Desaturate). Whatever technique you use, convert the B&W image back into RGB mode when you're done (<Image> Image -> Mode -> RGB). In this case I simply did a mode change to grayscale, then back to RGB mode.
Step 3
Double-click on the foreground color swatch to bring up the Color Selection dialog. Dial in the color RED=162, GREEN=138 and BLUE=101 (you can experiment with this color too; this is a good starting point though.)
Step 4
Bring up the Layers dialog (Ctrl+L) and click on the button for a new layer. Give it the name "Sepia Mask" and choose the option to fill it with the foreground color. Click OK. You should see nothing but the color now in the image window, since it obscures the image in the layer below. We are going to selectively apply this color to the image.
Step 5
Right-click on the Sepia Mask layer and select Add Layer Mask. In the Add Mask Options dialog, choose White (Full Opacity).
Step 6
In the Layers dialog, click on (select) the Background layer. Go up to the image window, select all and copy (Ctrl+A then Ctrl+C). In the Layers dialog, click on the layer mask icon in the Sepia Mask layer (the little white square). Then go back up to the image window and paste (Ctrl+V)
Step 7
In the Layers dialog, click the Anchor button to anchor the pasted image into the layer mask. In the image window, invert the color (<Image> Image -> Colors -> Invert). This layer mask insures that the shadow parts of the image receive most of the color, the mid-tones a little less, and the highlights little to none, much the way a print sepia-toned the traditional way would be.
Step 8
In the Layers dialog, change the Mode (blending mode) of the layer to "Color". This applies the color from the Sepia Mask layer according to the layer mask to the image. You now have your base result. It might be a good idea to save this under a new name at this point.
Step 9
Once you've got the base image, you can duplicate it (Ctrl+D), flatten the duplicate (<Image> Layers -> Flatten Image) and then experiment with: Hue and Saturation (<Image> Image -> Colors -> Hue..Saturation) Color Balance (<Image> Image -> Colors -> Color Balance) Levels or Curves (<Image> Image -> Colors -> Levels|Curves) etc. etc! You can always compare the result to the base image. If you want to start over, just duplicate the base image again and off you go. Hint: if GIMP had adjustment layers, like Photoshop, we'd just create one of those to experiment with further adjustments. Since GIMP does not have those, we have to flatten the image to apply some of the standard controls and filters. Ergo, work on a duplicate or save the base image.. Here I decided that the image was a little flat and so I punched up the contrast using curves.
Step 10
As a final touch, I ran the "Old Photo" Script-Fu without the "sepia" and "mottle" options. Here is the final image.
You can apply levels, curves or other adjustments to the contrast mask to increase or decrease "absorbency" of the sepia color into different areas of the image. The method by which you get a black and white image makes a big difference in how the sepia toning comes out.
The one on the left was from a grayscale conversion (<Image> Image -> Mode -> Grayscale); the one on the right started as a desaturate (<Image> Image -> Colors -> Desaturate). Notice that there is a lot more blue-channel noise in the right-hand one. This can add a nice "grain" effect (see tip above also) if that is what you are looking for. For this particular image, I prefer the smoother tonality and darker contrast of the left-hand image.
Intention
In this tutorial I'll show you how to do gaussian blur overlays using GIMP. This is an interesting technique that intensifies and saturates the colors in the image, increases contrast, and adds a slightly hazy, "dreamy" feel to the image. The basic technique is to create a duplicate layer in the image, lighten it and blur it, and combine it using a layer mode with the original. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a Photoshop tutorial on the luminous-landscape.com web site (great photography web site BTW; I recommend it).
The Procedure
Step 1
Open the Layers dialog. Right-click on the Background layer and select Duplicate (there is also a button for this in the bottom button bar of the Layers dialog ( ).
Step 2
Now double-click on the duplicate layer and rename the new layer "Blur Overlay". This step is not strictly necessary, but it is helpful to prevent confusion about what is on each layer, especially if you add some additional layers for other editing purposes, or more importantly, if you save the file with layers and open it six months later.
Step 3
In the Layers dialog, select the Blur Overlay layer. In the "Mode" drop-down box, select "Overlay". Now go back to the image window and apply a Levels (<Image> Image -> Colors -> Levels) or Curves (<Image> Image -> Colors -> Curves) and adjust it until the overall image has the proper brightness. You'll usually find it necessary to adjust the gamma slider (middle slider in
Levels) down. You are only adjusting the upper layer, but you are viewing the cumulative effect of the layer blend. Tip: If you don't get a good effect with Overlay mode, try Multiply mode (you can even change this while the Levels dialog is active). Tip #2: while the Levels dialog is active you can toggle visibility of the upper layer to see the original image and compare to the blend. Just click on the "eye" next to the upper layer.
Step 4
Go back to the image window and right click, selecting <Image> Filters -> Blur -> Gaussian Blur. You will need to experiment to find the best value, but typically a value between 10 and 30 will do nicely. Voila! If you don't like the effect, you can undo the blur (Ctrl+Z) and redo it (Shift+Alt+F) with a different value.
Click on the "eye" next to the Blur Overlay layer in the Layers dialog to rapidly compare the image with and without the overlay. Similarly, turn off the Background layer if you want to view the overlay to do further work on it.
Step 5
Duplicate the image (Ctrl+D). Flatten the duplicate (<Image> Layers -> Flatten Image).
Step 6
In the duplicate, run a threshold filter (<Image> Image -> Colors -> Threshold). In the threshold histogram, click and drag to the right to select all the pixels at the upper end of the scale. Retry or adjust the selection using the number controls in the dialog box until the display shows most of the pixels you want to preserve as white and all the rest black. You only need to approximate this, since we're going to clean up the mask anyway.
Step 7
To clean up the mask, I switched to the paintbrush ( ), hit "x" in the mask image to switch the foreground and background colors (Black/White to White/Black), selected a nice opaque brush in the Brushes dialog and painted the few pixels of the sky white that hadn't been turned white (the darkest parts of the clouds). Now the black parts. I switched the fg/bg colors back to (Black/White). I could have painted black all over the lake, but I had a faster idea in mind. I used the marquee selection tool ( ) to select the whole area and then using the fill tool ( it black in one fell swoop. ) I just clicked in the selection to fill
I then "feathered" the mask so that it will blend the layers without a harsh transition by applying a 6 pixel gaussian blur to the mask.
Step 8
Invert the mask (<Image> Image -> Colors -> Invert), so that the white parts correspond to the parts of the combined layers that you want to keep and the black parts correspond to the parts that should only reflect the original image (the highlights).
Step 9
Go to the Layers dialog. Select the overlay blur image in the "Image" drop down box (if it is not selected already). Right-click on the Blur Overlay layer and select Add Layer Mask. In the Add Mask Options dialog, select White (Full Opacity) and click OK. Now go back to the blurred threshold image, select all and copy (Ctrl+A then Ctrl+C). Go back to the overlay blur image and paste (Ctrl+V). Go to the Layers dialog and click the anchor button ( ) to anchor the mask.
Tip: Ctrl-click on the layer mask icon in the Layers dialog to toggle the effect of the layer mask to compare the image with and without the highlight mask.
Step 10
Here's the result. Compare to the original image (right image). I would flatten and apply a smart sharpening (edges) to finish it out.
Tips
Try other layer blending modes. "Multiply" often works well, but creates an even darker image than "Overlay"; you may have to really crank up the levels on the upper layer. One nice thing about Multiply is that you probably won't need the highlights mask. "Screen" has a milder effect than either "Overlay" or "Multiply" and will generally just intensify the colors/saturation. You may not want to lighten the upper layer at all, or perhaps even darken it. Experiment to see what effects you can get.
Other Examples
Using "Multiply" for the blending mode. (Final image on the right)
Using "Overlay" for the blending mode, plus a highlight mask for the sky and waterfall. (Final image on the right) The original tutorial (possibly with updated information) may be found here.
Intention
In this tutorial I'll show you how to salvage an image that has blown out highlights. This is a problem that is familiar to photographers shooting transparency film, which has an effective contrast range of about 5 stops. If you are not careful with your exposure you can easily lose all detail in your highlight areas, with no way to get it back: they "blow out" to clear (white). Many digital cameras have similar issues, especially consumer level ones. With these kinds of cameras it is worth paying attention to the old adage: "expose for the highlights". I find that if I treat my digital camera as if I were shooting slide film the exposure rules are about the same.
The Procedure
The basic technique is to graft matching areas of the image into the burned out parts using the clone tool and then to use several additional tools to blend the seams of the cloned areas.
Step 1
Here is the original image. I saw my cat go up into a lemon tree. Thinking there might be an interesting shot there, I grabbed the camera and shot him from several angles, including this shot through a hole in the foliage. When I saw the image later on the monitor I realized what a nice natural threedimensional frame I had. The camera was set on automatic exposure. While it did a great job of exposing for the dark cat in the shade of the tree, there are several spots where specular reflections of the bright sunshine overhead blew out. The worst and most noticable is the one off of the leaf at the top of the image. There are some less objectionable, but bothersome burned out areas to the lower right of the cat's face. Great image...could I rescue it?
Step 2
Using the color picker tool, you can see that there is no usable information left in the highlight. Pure white, of course, is 255/255/255.
If there had been some detail left here I might have tried a variation on the contrast masking technique or the "digital" neutral density filter first.
Step 3
The first step is to create a channel mask to be able to mask out parts of the image we don't want to affect. I'll use this for the main "pixel graft". Duplicate the original image (<Image> Image -> Duplicate or Ctrl+D). In the duplicate, select <Image> Image -> Colors -> Threshold. In the threshold dialog box, drag to select the very right (extreme highlights) portion of the histogram. Alternatively, you can type in the lower bound, as I did here (250).
This causes all the pixels in the image from 250-255 to go white and all the others to go black.
Step 4
Go back to the original image, and bring up the Layers and Channels dialog (<Image> Layers -> Layers, Channels & Paths, or Ctrl+L). Click on the Channels tab and add a new channel by clicking on the new channel button.
Step 5
Go back to the threshold image, <Image> Select -> All (Ctrl+A) and <Image> Edit -> Copy (Ctrl+C). <Image> Edit -> Paste it into the original image (it should go into the new channel). Click on the Layers tab and anchor the floating selection. You can close the threshold image now.
Step 6
Click on the Channels tab again, and right click on the new channel and select Channel to Selection (Ctrl+S). You may want to also click on the eye beside the channel to turn off visibility of the channel. Now feather the selection (<Image> Select -> Feather). I used a value of 15 pixels or so in this case. Finally (important!), click back on the Layers tab and select the Background layer, so the selection and further operations will apply to the image and not the channel mask.
Step 7
Now the real work begins. We've lost these pixels entirely, so we're going to have to graft some on from somewhere nearby using the clone tool. A description of how to use this tool is beyond the scope of this document (see the GIMP savvy to find out more about this tool). I cloned from the light part of the leaf just beyond the dark band to the right of the blown out area. This gave me a similar light-dark-light transition. You can see the clone tool options and the brush (<Image> Dialogs -> Brushes) I selected (at right).
Zoom in and clone until you have the area filled with a realistic facimile of the missing detail. Most likely it will have a noticable transition around the edges. That's OK, we'll fix that up next. <Image> Select -> None and zoom out to inspect your work.
Step 8
This step is where the most difficult work occurs. I must by necessity abbreviate this step, since it involves iterations of applying the following tools:
convolve (blur) Basically, smudge is your friend after a serious cloning job like this to clean up the transitions. Smudge around all the edges of the clone. The clone tool can also be used again here and there for "mop-up" work. I use the airbrush and convolve/blur tools to do fine touch up on the smudge job and make it totally seamless with the rest of the leaf. Tips: Make small changes so you can undo easily without having to redo a lot of work. Experiment with the tool options, especially opacity, rate and pressure (double-click on a tool to see the tool options). Some examples I used here are shown at right. Vary your brushes! You generally want a nice feathered edge for smoothing seams. Some examples I used here are shown at right. When using the airbrush, use the color picker first to sample a pixel. I average a pixel value as shown in the color picker options, right. Periodically, zoom in and out to examine your work. The zoom keys are incredibly handy for this ("=" key to zoom in, "-" key to zoom out). When you really think you are done, examine the image at full-screen. Remember that when you print something at 16x20 or 20x30 you may expose flaws in your retouching that you didn't see at small sizes. Right Image: zoomed view after the clone (previous step) and after this step.
Step 9
I went on to address the specular highlights to the lower right of the cat's face: spots of sunlit grass that burned out. These are not as bad, but I noticed them on a 16x20 print I had made and they bothered me, so toned them down a little. Here are the original (left image) and finished images (right image). The original tutorial (possibly with updated information) may be found here.
BLENDING EXPOSURES
Text and images Copyright (C) 2002 Eric R. Jeschke and may not be used without permission of the author.
Intention
In this tutorial I'll show you how to do blend two different exposures of the same scene that you would like to combine to get the best parts of both images. This procedure works best if you have:
1. 2.
(obviously) have shot two different exposures that would be pleasing to combine, had the camera mounted on a tripod (not strictly necessary, but helps greatly in aligning the images),
3.
the scenes are not too different at the boundaries of the blend. If the scene has changed too much (trees blowing, waves, people or cars moving, etc. between the images), especially at or near the "seams" of the blend, it will make the blend more difficult.
If you have only one image that needs exposure adjustment, you might look at using the "digital" neutral density filter or the contrast masking technique. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a Photoshop tutorial on the luminous-landscape.com photography web site (great web site BTW, I recommend it).
The Procedure
The basic technique is to create a layer above the image that contains the other exposure of the same scene. Finally, we apply a layer mask to the this layer which makes parts of the image transparent that we want to show through from below.
Step 1
Here are the two exposures, loaded into GIMP. I am going to sandwich these on different layers and then combine them with a layer mask.
Step 2
The first decision is which one goes on top. In this case I have decided to put the lighter image on top and the darker one on the bottom. The reason is because I hand-held the shots, and they are far from aligned. I'm going to have to move the bottom image until the arch is aligned as best I can get it. Also, the top image is the composition I want anyway, and I'll have less painting to do that way. Go the image that is going to be on the bottom. Open the Layers dialog (Ctrl+L) and click on the new layer button ( ) to create a new layer.
Step 3
Go to the image that is going to be on top. Select all and copy (Ctrl+A then Ctrl+C). In the Layers dialog, make sure the new layer is selected, then go to the bottom image window and paste (Ctrl+V). In the Layers dialog, click on the anchor button ( floating image. ) to anchor the
Step 4
Crank down the opacity of the upper layer so that you can see both images. If they are perfectly aligned you can skip the next step. Unless you used a digital capture on a tripod, the images probably need to be aligned. (Even if you had a film camera on a tripod, it is difficult to get two successive scans to feed through in perfect alignment.)
Step 5
In the Layers dialog, select the layer you need to move or rotate. In this case it is the lower layer. Using the arrow keys, nudge the image into alignment. You may need to rotate the image slightly too. When you get close to alignment, zoom in to get a good close-up view and get the best possible fit.
Step 6
In the Layers dialog, right-click on the upper layer and select Add Layer Mask. In the Add Mask Options dialog, select White (Full Opacity) and click OK.
Step 7
Now I want to paint black (transparency) onto the layer mask wherever I want the lower image to show through.
To minimize painting time, use the hand-select ("lasso" ) tool to select a large, handdrawn region just inside all the borders of the area you want to paint, as shown at right. Then using the fill tool ( ) fill the selection with black.
Step 8
Next, I select a large opaque brush from the Brushes dialog (Dialogs/Brushes), select the Paint tool ( ) and begin painting into the mask close to the boundaries of the blend.
Notice that I still have the opacity cranked down on the upper layer so that I can see both layers.
Step 9
For the very edges, I switch to a small, feathered brush and very carefully paint the edges. While I'm painting, I'll zoom in and out frequently ("=" key to zoom in, "-" key to zoom out) to inspect the work. Don't worry too much about the borders, since we'll probably have to touch those up anyway.
Step 10
Now the most painstaking part: blending the seams. This is a little tricky due to the different tonalities of the two exposures.
), Smudge (
), Airbrush (
) and Blur (
) are
Since I'm not sure if these tools have the ability to work across layers (as they do in Photoshop), I duplicate the image (Ctrl+D) and flatten the duplicate (<Image> Layers -> Flatten Image) and work on it. This has the additional benefit that if I ever mess up the blending job too badly I can always easily start over at this step. Note: see this tutorial on correcting blown out highlights for another example of using these tools for blending and some useful tips on their use. Here I've used primarily clone and a touch of smudge to blend the seams of the two exposures. I didn't do a very thorough job with this image, since it is more of an example and not something I'm planning to display at any significant size. Note: notice the chromatic aberration of the lens in the form of purple fringing at the edge of the arch. These tools are great for dealing with that even if I were not blending two exposures.
Final Step
Finished. The image still has some problems with blown out highlights in the sunlight of the rock face. It is also a little too dark in the foreground shadow.
The original tutorial (possibly with updated information) may be found here.
"SMART" SHARPENING
Text and images Copyright (C) 2002 Eric R. Jeschke and may not be used without permission of the author.
Intention
In this tutorial I'll show you how to do smart sharpening of your images. Applying an unsharp mask to an entire image is not always appropriate. A really good example of this is when you have an image with a lot of high ISO noise or film grain; applying across-the-board sharpening will enhance the noise/grain and make it even more visible, especially in large prints. Often there will be large areas of the image that you know you don't want to sharpen (e.g. a blue sky--the blue channel tends to get a lot of noise). This technique does two "smart" things to avoid sharpening noise: 1. 2. sharpen only the luminosity channel, and create a channel mask that contains only the edges in the image. Then you can load the channel mask as a selection and apply the unsharp mask to just the edges. Giving credit where credit is due: I did not come up with this method. I adapted it for GIMP from a Photoshop tutorial on the luminous-landscape.com photography web site (great web site BTW, I recommend it). New information and comparison with the "warp sharp" script!
The Procedure
You may want to maximize your browser window to properly see this tutorial. I didn't want to shrink the image windows down like I usually do for the other tutorials since sharpening and noise are subtle and really show up better at these larger sizes.
Step 1
Here's the original image loaded into GIMP. It is noticeably soft, probably due to bad autofocus. It really shows up in prints. Note: be sure to do any other editing that you want to on the image first, especially downsampling or upsampling (resizing). Sharpening should always be the last step that you do.
Step 2
Duplicate the image by pressing Ctrl+D or right-click and select <Image> Image -> Duplicate. It might be wise to minimize the original image window now. You can open it later to compare to the result. Right-click on the duplicate image and select <Image> Image -> Mode -> Decompose. In the decompose dialog box, select LAB (or HSV; see Note 1). Check the "As layers" checkbox (see Note 2) and click OK. This will create a new window with the image decomposed into the Luminosity ("brightness"), A and B channels as 3 layers. This will allow us to isolate and sharpen the luninosity channel which is a) the most important, and b) should be the cleanest in terms of noise. At this point I usually turn off visibility of the A and B layers in the Layers dialog by clicking on the "eyes". Note 1: if you happen to have an older version of the compose/decompose plug-in it may not have the LAB option. In that case use HSV (hue/saturation/value) instead. For any reference to the "LAB" image or "luminosity" channel below, substitute the "HSV" image/"value" window. The LAB option was not in my initial version of GIMP (ver 1.2.1), but I got the newer version of the plug-in at the GIMP Plug-in Registry and compiled it myself. Don't worry if you don't have it; HSV works great too. Note 2: in the older version of the decompose plug-in there is no "As layers" checkbox; instead it will create the three channels as separate windows rather than three layers in one window. It really doesn't matter if you do it this way; the layers way just reduces the clutter on your screen. If you don't have the "As layers" option, I suggest you minimize (but not
close) the hue and saturation (or A and B) windows. We'll need them later, but you don't want to accidentally pick one of them in the next few steps.
Step 3
Go to the duplicate image. Right-click and select <Image> Filters -> Edge Detect -> Edge. In the Edge Detect dialog box, select a parameter value of the appropriate size for the edges in your image. You may need to experiment with this. For the example image I chose 6. Now convert the edges image to grayscale by right clicking on it and selecting <Image> Image -> Mode -> Grayscale. This image is going to become our sharpening mask. Note: in some tutorials they recommend converting to greyscale and then running the edge detection filter. The premise there (my guess) is that perhaps you don't want to find noise as edges. My thinking is that there may be an edge in color, but not tonality (e.g. transition between two light colors). Once you have converted to greyscale you may not be able to detect that edge any more. Besides, with a high enough edge detection parameter (here 6) you will avoid detecting random CCD noise as edges.
Step 4
The next step is to adjust the tonality a little so that areas that need sharpening are really white and anything that doesn't need sharpening at all is really black. Open the Levels dialog (<Image> Image -> Colors -> Levels). Bring the black point up and the white point down to filter out any insignificant edges. You may need to play around with the
exact positions of the sliders. Click OK when the image outlines the significant edges in white and most everything else is black. How much you'll need to tweak this really depends on the image. There wasn't a lot of spurious edges shown here, so a small adjustment was all that was necessary.
Step 5
Now apply a gaussian blur (<Image> Filters -> Blur -> Gaussian Blur) to smooth out the edges a little. A radius of between 3 and 10 pixels (horizontal and vertical) should be enough. In the example I used 7.
Step 6
If you want to you can use Levels again to adjust the white and black points of the mask. I find this is usually a good idea after the blur. In this example I pulled the white point slider down a bit.
Step 7
Open the Layers dialog. Select the LAB image (if HSV, value) in the drop down box at the top and then click on the Channels tab.
Step 8
Right-click in the blurred/edges image window and <Image> Select -> All. Right-click again and select <Image> Edit -> Copy. (Alternatively you can use keyboard shortcuts Ctrl+A and Ctrl+C in succession). In the Layers dialog, make sure the Sharpening Mask channel is selected. Go back to the LAB (value) window and paste (<Image> Edit -> Paste or Ctrl+V).
Select the Layers tab in the Layers dialog and click on the anchor button ( anchor the floating image.
) to
Step 9
Click on the Channels tab in the Layers dialog. You should see a tiny version of the sharpening mask in the channel icon, indicating that you properly pasted the sharpening mask into the new channel. At this point you may wish to click on the eye icon to make the sharpening mask invisible.
Select the Sharpening Mask channel and click the "Channel to Selection" button ( You should see "marching ants".
).
You can experiment with feathering the selection here if you want; I usually don't.
Step 10
Important: in the Layers dialog, click on the Layers tab and make sure the luminosity layer (if HSV, Background layer of Value window) is selected, and is the only one selected. We only want to sharpen the luminosity channel. Apply an unsharp mask (<Image> Filters -> Enhance -> Unsharp Mask). You may want to experiment with the settings here. You will find that you can use much higher amounts of sharpening (than if the entire image were selected) without significantly degrading the image. In the example here I used Radius=1, Amount=2.0 (200% ?), Threshold=0. Now get rid of the selection (right-click and <Image> Select -> None) and zoom in (= key) to examine the results. If you're not happy with the results, undo and try the sharpen step again with different parameters.
Step 11
It's time to reconstruct our original image from the LAB (HSV) components. Right-click in the luminosity (value) window and select (<Image> Image -> Mode -> Compose). In the Compose Options dialog, make sure that you have selected LAB (HSV) on the left and on the right that the Luminosity, A and B (Hue, Saturation and Value) components are matched up with their respective images. Click OK; this should create a new composite image.
Final Step
Examine the resulting image, zooming in to examine edge detail. It may help to unminimize the original image for comparison. If you feel your image needs more/less sharpening, then go back to the LAB window, undo twice and redo the unsharp mask step above. When you are satisfied with the result you can close all the extraneous windows. The images on the right are zoomed to 100% and cropped: Left image: original image Center image: smart-sharpened image Right image: sharpened with a typical unsharp mask filter (Radius=1, Amount=1.0 (100% ?), Threshold=0) The smart sharpened image hardly shows any additional noise over the original image. Notice how the "regular" unsharp masked version at half the sharpening amount has much more visible noise, especially in the shadows on the side of the face and in the door frame of the car. Check out the shadow noise in the larger images on the smart sharpening shortcuts and variations page.
Tips
If this seems like too long and complicated of a process, you might be interested in looking at some shortcuts and variations that are still better than a simple sharpening step. Some very well-respected experts on image manipulation (e.g. Real World Photoshop, Blatner and Fraser--great book) suggest that mode changes in and out of RGB are not to be taken lightly. You can lose a suprising amount of information. For example, try the following experiment: 1. 2. 3. 4. 5. Open a new blank image. Using the gradient tool, create a gradient from black to white across it. Convert it to RGB (<Image> Image -> Mode -> RGB). Look at it's histogram (<Image> Image -> Colors -> Histogram). Convert it to LAB, by decomposing to LAB (<Image> Image -> Mode -> Decompose), then do a compose on the LAB image back to RGB (<Image> Image -> Mode -> Compose). 6. Look at the new image's histogram.
Left image: Gradient in RGB Right image: RGB -> LAB -> RGB
Left image: Histogram of the RGB image. Right image: Histogram of the RGB -> LAB -> RGB image.
Left image: Zoom 400% of the RGB image. Right image: Zoom 400% of the RGB -> LAB -> RGB image. Look at all the information that has been lost in the converted image! There is obvious posterization in the zoomed close up. You are now thinking to yourself, "Good grief! Why on earth would he suggest changing modes to sharpen the luminosity channel if it has this kind of effect?" Look at the histograms of the original image and the one smart sharpened on the luminosity channel:
Left image: Histogram, original image Right image: Smart-sharpened on luminosity channel You can see that in practice, changing modes does not always have this drastic of an effect. What should you do? I suggest trying it and look at the histogram! This is the beauty of the digital darkroom. If your image is not that noisy anyway, then no need to change modes, as suggested in the shortcuts. However, this does point out a general piece of advice, which is to use the histogram regularly. It is a great tool to monitor what is happening to your image "numerically" as you edit it.
Other Examples
First image: Original (pretty noisy) Left image: Standard unsharp mask Right image: Smart sharpened This example is kind of contrived. It doesn't really need much sharpening in the first place, and the smart-sharpened version looks over-sharpened. I include it here mainly because it is pretty noisy, so it really shows what happens when you sharpen noise, and how the smart sharpening technique doesn't affect the noise. For details on reducing CCD noise (using this image as an example), see this tutorial.
Left image: Edge sharpened (Amt=1.25) Right image: Standard unsharp mask (Amt=0.50)
Further Reading
Almost Everything You Wanted to Know About Sharpening in Photoshop Follow-up article to the above, A Two-Pass Approach to Sharpening in Photoshop Fred Miranda: The Ultimate Sharpening Technique
The original tutorial (possibly with updated information) may be found here.
PERLOTINE TUTORIAL
Text and images Copyright (C) 2002 Carol Spears and may not be used without permission of the author.
Intention
I made a pretty neat image map for my web site. These three tutorials demonstrate some of GIMP's html rendering plug-ins that I used to make the image map. In this tutorial, the first of three, I am going to demonstrate how to run perlotine a couple of times to slice an image up and put it back together in some nested tables. Since I am going to make a web page that emulates the GIMP palette colorpicker, I "Acquired" a screenshot of the dialog with the Visibone2 palette selected. Here is a screenshot of the screenshot of the dialog with the guides placed for the first step. For the design of my colorpicker, it will be better to run perlotine once over the image for the rows and then again for each rows columns. I want to leave the image map area in one block and also, I want to put html text box in the logical place and a couple of buttons at the
bottom. Each row needs a different width of columns. It will probably be clearer once we make the slices ....
Step 1
Perl-O-Tine is a plug-in that slices an image along guides that you have placed and writes the html table that will put it back together again on a web page. If you are using GIMP after experience with Photoshop LE, you might not be aware of guides or their usefulness. Put the curser on the ruler and drag toward the image.
I zoomed in 4 times on my screenshot so I could make neat slices. Once you have the guides in place, you can find the plug-in under <Image>Filter->Web>Perlotine.
Step 2
"Save path:" tells GIMP where to put the slices. "Html file name:" names the perlotine html. The
Perlotine plug-in names the images very smartly, with the position name. My first round of slices were named imap-table1 and second round, imap-table2. I opted for png, to be politically correct on a gimp.org site. Last, since I am running the plug-in a few times, I opt for the separate directory to keep the images apart. Sooner or later, you will have to click the "Ok" button for the plug-in to work.
Step 3
This is the product of the first slicing with Perlotine. This is a 3 element table. We will be slicing the middle section again, for the GIMP Table Magic Plug-in in the third tutorial, yet to be written. The bottom section will be sliced up to contain a dialog box for the color number to return to for both color pickers, so we will slice that next. Below is the html that Perlotine generated. As I slice the smaller parts, this first html will be a base that the new tables should easily slide into. You can shift-right-click on the pieces to see how it worked.
<table cellspacing="0" cellpadding="0" border="0"> <tr> <td><img alt=" " src="imap-table1-0-0.png" width="290" height="73"></td> </tr><tr>
<td><img alt=" " src="imap-table1-1-0.png" width="290" height="177"></td> </tr><tr> <td><img alt=" " src="imap-table1-2-0.png" width="290" height="17"></td> </tr><tr> <td><img alt=" " src="imap-table1-3-0.png" width="290" height="21"></td> </tr><tr> <td><img alt=" " src="imap-table1-4-0.png" width="290" height="50"></td> </tr> </table>
This is the second slice. The dialog box has been put into its own element. By slicing it separately, I avoided slicing the image map.
<table cellspacing="0" cellpadding="0" border="0"> <tr> <td><img alt=" " src="imap-table1-3-0-0.png" width="10" height="21"></td> <td><img alt=" " src="imap-table1-3-0-1.png" width="219" height="21"></td> <td><img alt=" " src="imap-table1-3-0-2.png" width="61" height="21"></td> </tr> </table>
Here is the new table. It has 7 elements. The piece 4 rows down and 2 elements to the left can be filled with a textbox now. There are two ways to add the new table. I chose the more difficult of the two, as I am using css and css doesn't seem to like nested tables. So I made the previous elements span 3 columns. If you don't know how to tweak html like this, you can just nest them like I did here. I am making all of the rest of the cuts in one step now. First the tweaked code for this table and then the completely chopped up table, blown out to see the pieces and put back together again, so you can believe it. And that code. By then you should be able to do any sort of slicing you need.
<td colspan="3"><img alt=" " src="imap-table1-00.png" width="290" height="73"></td> </tr> <tr> <td colspan="3"><img alt=" " src="imap-table1-10.png" width="290" height="177"></td> </tr> <tr> <td colspan="3"><img alt=" " src="imap-table1-20.png" width="290" height="17"></td> </tr> <tr> <td><img alt=" " src="imap-table1-3-0-0.png" width="10" height="21"></td> <td><img alt=" " src="imap-table1-3-0-1.png" width="219" height="21"></td> <td><img alt=" " src="imap-table1-3-0-2.png" width="61" height="21"></td> </tr><tr> <td colspan="3"><img alt=" " src="perlotine1/imaptable1-4-0.png" width="290" height="50"></td> </tr> </table>
Exploded View
Assembled View
<!--
-->
<table cellspacing="0" cellpadding="0" border="0"> <tr> <td colspan="3"><img alt=" " src="imap-table1-00.png" width="290" height="73"></td>
</tr> <tr> <td colspan="3"><table cellspacing="0" cellpadding="0" border="0"> <tr> <td><img alt=" " src="imap-table1-1-0-0.png" width="15" height="177"></td> <td><img alt=" " src="imap-table1-1-0-1.png" width="241" height="177"></td> <td><img alt=" " src="imap-table1-1-0-2.png" width="34" height="177"></td> </tr> </table> </td> </tr> <tr> <td colspan="3"><img alt=" " src="imap-table1-20.png" width="290" height="17"></td> </tr> <tr> <td><img alt=" " src="imap-table1-3-0-0.png" width="10" height="21"></td> <td><img alt=" " src="imap-table1-3-0-1.png" width="219" height="21"></td> <td><img alt=" " src="imap-table1-3-0-2.png" width="61" height="21"></td> </tr><tr> <td colspan="3"><table cellspacing="0" cellpadding="0" border="0">
<tr> <td><img alt=" " src="imap-table1-4-0-0.png" width="5" height="6"></td> <td><img alt=" " src="imap-table1-4-0-1.png" width="277" height="6"></td> <td><img alt=" " src="imap-table1-4-0-2.png" width="8" height="6"></td> </tr> <tr> <td><img alt=" " src="imap-table1-4-1-0.png" width="5" height="36"></td> <td><img alt=" " src="imap-table1-4-1-1.png" width="277" height="36"></td> <td><img alt=" " src="imap-table1-4-1-2.png" width="8" height="36"></td> </tr> <tr> <td><img alt=" " src="imap-table1-4-2-0.png" width="5" height="8"></td> <td><img alt=" " src="imap-table1-4-2-1.png" width="277" height="8"></td> <td><img alt=" " src="imap-table1-4-2-2.png" width="8" height="8"></td> </tr> </table></td> </tr> </table>
Intention
In my opinion, it is hard to come up with a good application for an image map. For many online applications, it is simply overkill. However, to emulate the behavior of a GIMP Dialog seems to be a perfect place for this powerful web tool. The image to the left comes from a previous tutorial about how to use perlotine. The tutorial slices this image further, but since the GIMP Image Map Plug-in and image maps in general use coordinates, we can use a less complicated table for this. Above is a screenshot of the GIMP Image Map Plug-in, it has been scaled down for a nicer page. It can be somewhat scary at first. I tried to arrow and number the few areas I am worried about for this tutorial. So, relax.
1. Goodies->Create Guides
This is a screenshot of the Create Guides Dialog (left image). We get to change every single option before we are done. Whee! I came to this tutorial prepared with a perfectly wonderful colorpicker script that I stole from Victor S. Engel. The only problem with his colorpicker is that it didn't look like GIMP. :) If you "View Source" of that page, you can see that there is a similar line to each image map coordinate area. So, into the "Base URL" box, put the stuff that will be the same on each. I am going to deal with the colors (256 of them, eek!) after I make the image map. So, put javascript:GetClick()" onmouseover="GetColor(' into the bottom box. The Image Map Plug-in will put the href=" into the html for you. Once I started to write this tutorial, I discovered that the Image Map Plug-in has the ability to do the zooming and such. Too late, for me, I guess as I used GIMPs tools for measuring to determine the information for the rest of the Create Guides information. The original image was still open, so it was hard not to think about using it. Here is a screen shot of <Image> View -> Zoom -> 4:1
I used GIMP's nifty measure tool to determine that the rectangles are all 10 pixels tall and 14 pixels wide. The black lines in between are only one pixel wide also. You can do the math or count the squares, but the Visibone2 palette has 16 colors across and 16 colors down. I used the mouse on guides to determine the start point of the first image map area. That is all of the configurable things in this dialog. Time to click "Apply".
2. Map Image
Once you hit "Apply" the guides will draw themselves on the image map preview window. You can see if you hit the right places on your image. This tutorial certainly makes it look like I got it right the first time ;) At this point, for this project, you can jump right to "4. File Save"as it is totally done for our use.
3. Table Editor
Since 256 elements is way to much to edit by hand, so I ended up using a different way to finish the information at each point. However, I played with the editor a bit. It was easy to use and figure out. Highlight the text in the pictured portion of the Image Map Dialog area by clicking on the area in the image preview. (shown above). Honestly, I don't have that much experience with html renderers, if you have the experience and would like to fill this portion of the tutorial in with something smart about editing your image map elements, feel free. I fully admit that I only used a small small part of this great plug-ins ability. 256 elements was out of the reach of my short attention span.
4. File->Save As
I am not going to bore you with the directions to File->Save As. Instead, check out my product here. It needs the colors placed at the end of the lines. This information is already found in the GIMP Palette directory, usually located at ~/.gimp-1.2/palettes/. This was the Visibone2 palette. I posed this problem to my friend Bex and went to sleep. When I awoke, she had solved my dilemma by writing the bextruder shell script. This puppy takes each line from Visibone2.txt, gets a color from the Visibone2 in your home directory and puts it on the end of the line. Then plops a ')> on the end of that, producing a file called visibone.html. This didn't work. bex did exactly what I told her to do and I had forgotten a ". The plop at the end should have been a ')">. It was easy enough to fix with any editors global replace thingie .... My "working chunk of html" is called bexcolored.html. The script should be easy to edit to use any palette. That is why I brought up the missing". If all goes well, clicking on this little pop-up containing this htmlized html of an online colorpicker should put your color choice into this box here -->
#
Intention
A plug-in is of limited use if it has nothing to do with the image. In this section, we explore the exciting world of GIMP image hierarchy, and learn how to manipulate it.
In the beginning, there was Wilber, Wilber the gimp. The graphic was without form and void, and darkness was upon the face of the desktop, and the Spirit of Wilber was moving over the face of the bitstream. And Wilber said, "<Toolbox>File->New," and there was an image. And Wilber saw that the image was good, and Wilber
separated the image into drawables. And Wilber looked down at what he had wrought, and Wilber said, "Oh golly." For Wilber had made the drawables of the layer according to their kinds, and the drawables of the channel according to their kinds, and the drawables of the mask according to their kinds ...
... or you could look at it the other way around. We have all sorts of silly things like masks, channels, and layers, but they're all just a bunch of pixels that can be drawn on, so we treat them much the same and lump them all in to the category of "drawables". And an image, then, is just what you get when you put some drawables together. Most plug-ins care suprisingly little about these images. After all, it's the bunch of pixels on the drawable most of them are playing with. In any case, the most complex data structure a plug-in uses for an image is an integer (gint32), a simple ID by which GIMP knows that image. Drawables make life much more exciting. <snip> The original document can be found here.
BASIC PERL
Text and images Copyright (C) 1999-2002 Dov Grobgeld and may not be used without permission of the author. Editor's note: this tutorial was originally written for GIMP 1.2. Parts of it will not work with GIMP 2.x and later versions due to changes in font handling and PDB API.
Intention
So far most of the script programming for GIMP has been done using Scheme through ScriptFu. Unfortunately the Scheme environment GIMP provides is very primitive, e.g. without any reasonable error handling. Furthermore, must users are not familiar with Scheme as a language. Some users may therefore prefer to write scripts for the GIMP in Perl. Perl as a language is probably more familiar to web-literate users as it is the major language for writing CGI scripts. Now, GIMP scripts may also be written with Perl. This tutorial will describe how to write such plug-ins and scripts for GIMP.
As there are several excellent tutorial texts describing the Perl language, this tutorial will assume a working knowledge of Perl, and will instead concentrate on the use of GIMP together with the use of the Perl modules Gimp and Gimp::Fu, written by Marc Lehmann pcg@goof.com. NOTE: This tutorial was originally written for a 1.2 version of GIMP. It was proofread and some updates were applied as of March 22, 2007. However, the sample scripts which are shown on this page have not been re-tested to verify that they will work with the current 2.2 version of GIMP.
Perl and all its associated modules are available in source form from the Perl Comprehensive Archive Network, CPAN. It is also possible to download them in RPM format from the ftp.gimp.org website.
#!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu; # Register extension to GIMP register ... ; exit main(); # Handle over control to GIMP
The interesting items to note in the script are the use of the two modules Gimp and Gimp::Fu, the register function (which will be described in detail below), and the way control is handed over to the Gimp module on line 6. The use of the ":auto" statement makes Perl automatically include all of the GIMP PDB functions and constants into the Perl name space.
Name:
gimp_image_new
Blurb:
Creates a new image with the specified width, height, and type.
In:
INT32
width
INT32
height
INT32
type
Out:
IMAGE
image
Help:
Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp_display_new' with this image as an argument will fail. Layers can be created using the 'gimp_layer_new' command. They can be added to an image using the 'gimp_image_add_layer' command
All the the constants mentioned in the PDB Explorer have been defined within Gimp::Fu and may be used within Perl. E.g. a call to create a new image of size 100x150 of type RGB looks as follows:
The PDB entry above shows that gimp_image_new is called with three parameters (width, height, type). These are all of type INT32. This type, and other types, will be explained below. Script-Fu scripts are called just like any other script according to the PDB signature in the PDB browser. E.g. to run the Script-Fu Basic One logo just do: script_fu_basic1_logo("Hello", 72, "-*-utopia-*-r-*-*-72-*-*-*-*-*-*-*", [0,0,0],[1,1,1]); Unfortunately, as of this writing, calling Script-Fu from Perl has proved to make both Script-Fu and GIMP very unstable and caused both of them to crash. If any of the readers is able to describe what is needed to get it to run successfully, I will happily include this in a future version of this tutorial. NOTE: When calling a PDB function from Perl::Gimp that has an image and a drawable as the two first arguments, only the drawable should be given as argument in the calling sequence.
If form 1. is given, then the script is a standalone script that appears in the menu hierarchy under Xtns/Perl-Fu and takes all of its inputs through the Gimp::Fu interface frame. If form 2. is given, on the other hand, the script is tied to the image menu popped up through use
of the right-hand mouse button over any image. In this case Gimp::Fu will add, as the first two parameters to the script, the ID of the image and the drawable which was active when the script was invoked. 8. The acceptable image types - a string. This list contains a list of image types acceptable. This field is only used for scripts that are in the "<Image>" hierarchy. For images in the <Toolbox> hierarchy, this should be an empty string. Possible values are listed in the table below:
value
meaning
RGB
RGB images
RGBA
GREY
9. 10. Parameters - A reference to an array of parameters. (A reference to an array in Perl is simply an array written within square brackets). Each parameter in turn is a reference to an array containing the following four or five values: 1. The type of the parameter. The types recognized by Gimp::Fu and Perl are given in the following table:
Type
Possible forms
Comment
42
PF_VALUE PF_FLOAT
3.141
PF_TOGGLE PF_BOOLEAN
0 1
A boolean value.
PF_SLIDER PF_SPINNER
An integer value through a slider and a spinner interface. The range parameter should be specified and is interpreted as minimum, maximum, and step, e.g. [0,100,1].
PF_FONT
-*-blippo-*-*-*-*-24-*-*-*-*-*-*-*
PF_STRING
"A string"
A string
PF_COLOR PF_COLOUR
[255,127,0] #ff7f00
A color may either be expresse reference to an array of three components, or as a hexadecim proceeded by the hash sign.
PF_TOGGLE
0 1
A boolean toggle
PF_IMAGE
An image
PF_DRAWABLE
A drawable.
PF_BRUSH
A brush
PF_GRADIENT
A gradient
PF_PATTERN
A pattern
2. 3. 4. The name of the parameter - a string A help text for the parameter
5.
Default value for the parameter. This should be given in the form listed in the table above.
6.
An array defining allowed range for the value. This is only possible for PF_SLIDER and PF_SPINNER.
11. A reference to an array of return types of the sub in the 11th parameter. 12. The sub to be called - a reference to a sub . This subroutine will be called with the associated menu entry declared through the Menu path described above. When the sub is called it is passed as arguments the list of parameters declared in field 9, described above, and in the case of a "<Image>..." script, the active image and layer as first and second parameters. A reference to a sub in Perl may be declared in two ways. You can declare a subroutine at a different place in the source file (e.g. sub run) and reference it by writing \&run. An alternative way is to write it inline by simply writing: sub { ($text, $color) = @_ ; ... }
The sub is expected not need to display a new image after it has created it. Instead it is expected to return the new image or images that were created in accordance with the return types declared in parameter 10 of the register call described above. This behaviour has been added in order to be able to call the sub non-interactively. More about that behaviour below.
#!/usr/local/bin/perl -w use Gimp ":auto"; use Gimp::Fu; sub img_uni { my ($size, $color) = @_; # Create a new image $img = gimp_image_new($size, $size, RGB);
# Create a new layer $layer = gimp_layer_new($img, $size, $size, RGB, "Layer 1", 100, NORMAL_MODE); # add the layer to the image gimp_image_add_layer($img, $layer, -1); # Set the background to the required color gimp_palette_set_background($color); # Paint the layer gimp_edit_fill($layer, BG_IMAGE_FILL); # Return the image return $img; } register "img_uni", "Create a uniform image", "A tutorial script", "Dov Grobgeld", "Dov Grobgeld (c)", "1999-05-14", # fill in name # a small description # a help text # Your name # Your copyright # Date # menu path
exit main();
Most of these commands are directly copied out the PDB. This script shows the essential steps of producing a stand-alone script:
line(s)
Description
10
13-14
17
19-23
26
29-42
To test the script, save it in the directory $HOME/.gimp-2.2/plug-ins. It must then be made executable through the command: chmod +x $HOME/.gimp-2.2/plug-ins/uni Then start GIMP. It is generally a good idea to test the syntax of the script with perl -c before starting GIMP. (A more official way to add scripts is to use the gimptool --install-bin command). Note: It is not possible to add scripts once GIMP is running. On the other hand, it is possible to change a script which has already been registered, as long as the parameters don't change.
The script is now accessible through the menu system through the Xtns top menu.
When choosing this menu entry the following screen is popped up.
Choosing the default values creates a result like the image above.
Gimp::Fu provides an alternative object-oriented syntax for the image and the drawable commands. Here is a table showing the procedural vs the object oriented syntax for a few commands:
procedural syntax
gimp_image_add_layer($drw,-1);
$img->add_layer($drw, -1);
gimp_drawable_width($drw);
$drw->width();
The substitution rule for converting a PDB function call into a method is as simple as erasing ``gimp_image_'' from the beginning of the function call and calling this method through the image object. Similarly for the gimp_drawable_... functions. Note that the object oriented syntax is only syntactic sugar that makes the calling syntax cleaner in some cases. The error messages are still given in the procedural format.
Name:
gimp_edit_fill
Blurb:
In:
DRAWABLE
drawable
INT32
fill_type
The type of fill: FG_IMAGE_FILL (0), BG_IMAGE_FILL (1), WHITE_IMAGE_FILL (2), TRANS_IMAGE_FILL (3), NO_IMAGE_FILL (4)
Help:
This procedure fills the specified drawable with the fill mode. If the fill mode is foreground, the current foreground color is used. If the fill mode is background, the current background color is used. Other fill modes should not be used. This procedure only affects regions within a selection if there is a selection active.
Thus, if a selection is active when gimp_edit_fill is called only the selection is painted. There are lots of ways of choosing a selection as can be seen when searching for a ``select'' in the PDB. The example below uses gimp_rect_select, whose entry in the PDB looks as follows:
Name:
gimp_rect_select
Blurb:
In:
IMAGE
image
The image
FLOAT
FLOAT
FLOAT
width
FLOAT
height
INT32
operation
the selection operation: {ADD (0), SUB(1), REPLACE (2), INTERSECT (3) }
INT32
feather
FLOAT
feather_radius
Help:
This tool creates a rectangular selection over the specified image. The rectangular region can be either added to, subtracted from, or replace the contents of the previous selection mask. If the feather option is enabled, the resulting selection is blurred before combining. The blur is a gaussian blur with the specified feather radius.
A simple use of this function which selects a rectangle in the middle of an image and paints that rectangle with a user defined color. This example also introduces a couple of new features we haven't seen before: The script is associated with an image since its menu path starts with "<Image>/...". Note that as a result of this the callback sub in line 13 receives two additional parameters, the active image and the seleced drawable. The use of a subroutine without a name as a parameter to register The use of the PDB functions gimp_undo_push_group_start and gimp_undo_push_group_end. These functions declare an undo group. When an undo is done on the image, instead of having the individual operators undo, all the actions between the undo start and the undo group calls will be undone at once. The return type of the register function defines what new images should be displayed by GIMP. In this case we don't want to display any new images and therefore return an empty array.
#!/usr/local/bin/perl -w use Gimp ":auto"; use Gimp::Fu; register "img_paint_select", "Paints the selection", "Paints the selection", "Dov Grobgeld", "Dov Grobgeld", "1999-05-14", "<Image>/Perl-Fu/Tutorial/Paint Select", "*", [ [PF_COLOR, "color", "Rectangle color", [0,0,255]] ], sub { my($img, $layer, $color) = @_; my($width, $height) = (gimp_image_width($img), gimp_image_height($img)); # Select a rectangle inside the image and paint it with color
gimp_undo_push_group_start($img); gimp_rect_select($img, $width/4, $height/4, $width/2, $height/2, REPLACE, 0,0); gimp_palette_set_background($color); gimp_edit_fill($layer, BG_IMAGE_FILL); gimp_selection_none($img); gimp_displays_flush(); gimp_undo_push_group_end($img); # Tell GIMP not to display a new image return (); }; exit main();
Once the channel is finished, the channel may be loaded into the selection through the PDB function gimp_selection_load(). Search for ``select'' in the DB Browser to see a list of all the selection related functions.
6.2 Loops
In Perl it is trivial to write loops that, together with the various selecton tools, give powerful creative possibilities. Here is an example that mixes colors in circles. There is nothing really new here, but it shows the power of what we have described above.
#!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu; sub circles { my ($size, $bgcolor, $radius) = @_; # Create the background $img = gimp_image_new($size, $size, RGB); $layer = gimp_layer_new($img, $size, $size, RGB, "Layer 1", 100, NORMAL_MODE); gimp_image_add_layer($layer, -1); gimp_palette_set_background($bgcolor); gimp_edit_fill($layer, BG_IMAGE_FILL); my $ncircles = int($size/$radius/2); for ($i=0; $i<$ncircles; $i++) { for ($j=0; $j<$ncircles; $j++) { # Be creative and mix colors $color = [$i*30, ($ncircles-$j)*25, ($i+$j)*15]; # Select a circle gimp_ellipse_select($img, $i*$radius*2, $j*$radius*2,
$radius*2, $radius*2, REPLACE, 1, 0, 0); # Paint the color in the circle gimp_palette_set_background($color); gimp_edit_fill($layer, BG_IMAGE_FILL); gimp_selection_none($img); } } return $img; } # register the script register "circles", "a loop", "a loop", "Dov", "Dov", "1999-05-14", "<Toolbox>/Xtns/Perl-Fu/Tutorial/Circles", "", [ [PF_INT32, "size", "Img size", 100], [PF_COLOR, "bg", "Background color", [40,180,60]], [PF_INT32, "radius", "Circle radius", 10] ], \&circles; exit main();
The result.
#!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu; sub text1 { my($font, $text) = @_; # Create a new image $img = gimp_image_new(350, 100, RGB); # Create a new layer and draw it to the image at the top $drw = gimp_layer_new($img, $img->width, $img->height, RGB, "BG", 100, NORMAL_MODE); $drw->add_layer(-1); gimp_palette_set_background("black"); gimp_edit_fill($drw, BG_IMAGE_FILL); # Choose color of text gimp_palette_set_foreground([255,255,0]); # Create the text
my $border = 10; my $text_layer = gimp_text_fontname($drw, $border, 1, xlfd_size($font), $font); gimp_floating_sel_anchor($text_layer); return $img; } # register the script register "hello_world1", "basic text", "basic text", "Dov", "Dov", "1999-05-14", "<Toolbox>/Xtns/Perl-Fu/Tutorial/Basic text 1", "", [ [PF_FONT, "font", "font", "-*-utopia-bold-r-*-*-70-*-*-*-*-*-**"], [PF_STRING, "text", "text", "Hello world!"] ], \&text1; # Handle over control to GIMP exit main(); 0, 0, $text,
The result above: The script makes use of the function xlfd_size which extracts the size of the font from the X11 font name. This is necessary as the authors of gimp_text_fontname decided that the font size within the fontname is ignored. One thing to note in this script is that the text that is created on line 24 is a floating layer, than needs to be anchored to its parent layer. This is done in line 27 through the call to gimp_floating_sel_anchor(). This script suffers from the problem that the image size is unrelated to the text size. This is taken care of in the following more complex example which shows the basic steps for a logo generating script. Creation of an image arbitrary size Creation of a background drawable of an arbitrary size Creation of text layer which exactly fits the text with the command gimp_text_fontname(). Resizing the image and the background to the size of the text layer. The result is an image composed of two layers; a transparent text layer on top of a uniform background.
#!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu; sub basic_logo { my($font, $border, $text, $bgcolor, $fgcolor) = @_; # Create a new image of an arbitrary size with $img = gimp_image_new(100, 100, RGB); # Create a new layer for the background of arbitrary size, and # add it to the image my $background = gimp_layer_new($img, 100, 100, RGB, "Background", 100, NORMAL_MODE); gimp_image_add_layer($background, 1);
# Choose color of text gimp_palette_set_foreground($fgcolor); # Create the text layer. Using -1 as the drawable creates a new layer. my $text_layer = gimp_text_fontname($img, -1, 0, 0, $text, $border, 1, xlfd_size($font), $font); # Get size of the text drawable and resize the image and the # background layer to this size. my($width, $height) = ($text_layer->width, $text_layer->height); gimp_image_resize($img, $width, $height, 0, 0); gimp_layer_resize($background, $width, $height, 0, 0); # Fill the background layer now when it has the right size. gimp_palette_set_background($bgcolor); gimp_edit_fill($background, BG_IMAGE_FILL); return $img; } # register the script register "basic_logo", "basic logo", "basic logo", "Dov Grobgeld", "Dov Grobgeld", "1999-06-09", "<Toolbox>/Xtns/Perl-Fu/Tutorial/Basic Logo", "", [ [PF_FONT, *-*-*-*-*"], [PF_INT, "font", "font", "-*-utopia-bold-r-*-*-70-*-*-
"border",
[PF_STRING, "text",
Note the special syntax of gimp_image_text_fontname() in line 23 in basic-logo with an image specified for a first parameter, and the drawable = -1. This is in contradiction to the rule above that the image should not be specified for PDB functions that take both an image and a drawable as the first two parameters. But since the drawable=-1, which has no image related to it, an image explicitly be provided. The special case drawable=-1 means that instead of creating a floating layer, a new image layer will be created. The result shown in the dialog and the resulting image above.
8. Floating selections
When a region has been selected through one of the selection routines, the area outlined by the selection may be copied to the cut-buffer through the gimp_edit_copy command. The cutbuffer may subsequently be pasted into a different layer through the gimp_edit_paste command. When a layer is pasted it becomes a floating selection. This floating selection may be moved to its required position by the command gimp_layer_set_offsets, and finally it is pasted by the gimp_floating_sel_anchor command. Another way of determining the position of a pasted layer is to create a selection in the target image before the cut-buffer is pasted. This is illustrated in the following program, which works on one image and takes as a parameter an another image, which it concatenates to the right of the first image. The lines 28-38 shows how the second image is copied and glued into the first image.
#!/usr/local/bin/perl use Gimp qw( :auto ); use Gimp::Fu; sub horiz_cat { my($img1, $drw1, $drw2) = @_; # Get image 2 $img1 = $drw1->image(); my $img2 = gimp_drawable_image($drw2); # Get sizes through OO syntax my($w1, $h1) = ($drw1->width, $drw1->height); my($w2, $h2) = ($drw2->width, $drw2->height); # The new height is the maximum height of the images my $hmax = $h1 > $h2 ? $h1 : $h2; # Create an undo group gimp_undo_push_group_start($img1); # Resize the drawable layer to make room for the img gimp_image_resize($img1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2); gimp_layer_resize($drw1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2); # Copy $drawable2 and paste it into the new space of $drawable1 # select all of img2
gimp_selection_all($img2); # copy it to the clipboard gimp_edit_copy($drw2); # make a selection in img 1 in the position where it is to be pasted gimp_rect_select($img1, $w1, ($hmax-$h2)/2, $w2, $h2, 0,0,0); # paste and then anchor it my $floating_layer = gimp_edit_paste($drw1, 0); gimp_floating_sel_anchor($floating_layer); # Close the undo group gimp_undo_push_group_start($img1); # Update the display gimp_displays_flush(); return undef; } # register the script register "horiz_cat", "Horizontal concat", "Horizontal Concat", "Dov Grobgeld", "Dov Grobgeld", "1999-05-4", "<Image>/Perl-Fu/Tutorial/Horizontal Concat", "*", [ [PF_DRAWABLE, undef], ], \&horiz_cat; # Handle over control to GIMP "drawable", "Drawable to concatenate",
exit main();
Writing fullfledged plug-ins that manipulate the tile data through the Perl Data Language (PDL) module. Using Perl::GIMP in a CGI environment. How to fill with gradients in a plugin How to do "free selections". The original tutorial can be found here and an updated version for GIMP 2.0 can be found here.
Table of contents
1. Background 2. What you need 3. The Gimp module 4. The GIMP PDB 4.1. Gimp::Fu and the register function 4.2. A commented script 5. Object oriented syntax 6. Painting areas with selections 6.1. Complex selections 6.2. Loops 7. Creating text 7.1. Hello World - writing text in an image 8. Floating selections 9. The Perl Server and stand-alone scripts 9.1. A shell for gimp-perl 10. End notes 11. Links and references
1. Background
One of the wonderful features of GIMP is that it all its functionality may be accessed through scripting. So far most of the script programming for Gimp has been done through Scheme through Script-Fu. Unfortunately the Scheme environment Gimp provides is very primitive, e.g. without any reasonable error handling. Furthermore, must users are not familiar with scheme as a language. Some users may therefore prefer to write scripts for the Gimp in Perl.
Perl as a language is probably more familiar to the web-literate users, as it is the major language for writing CGI scripts. Now, Gimp scripts may also be written
with Perl. This tutorial will describe how to write such plug-ins and scripts for Gimp. As there are several excellent tutorial texts describing the perl language, this tutorial will assume at working knowledge of Perl, and will instead concentrate on the use GIMP together with the of the perl modules Gimp and Gimp::Fu, written by Marc Lehmann, pcg@goof.com.
Perl and all its associated modules are available in source form from the Perl Comprehensive Archive network, CPAN. It is also possible to download them in RPM format from the ftp.gimp.org website.
The interesting items to note in the script is the use of the two modules Gimp and Gimp::Fu, the register function, which will be described in detail below, and the way the control is handed over to Gimp module on line 9. The use of the ":auto" statement makes perl automatically include all of the gimp PDB functions and constants into the perl name space.
All the PDB functions may be called from perl, as will be seen below. These PDB functions are either internal to gimp, or have been made available through a plug-in or a script extension, but as far as the caller is concerned there is no difference. As we will see below, when a perl function is registered through the register function, it will appear in the PDB as well.
Gimp/perl comes with a PDB browser available in Xtns>PDB Explorer. (There is another PDB browser available in Xtns>DB Browser but the PDB Explorer is more suited for Perl users.) This browser provides a way of seeing all the functions in the PDB, as well as their input and output parameters. E.g. the PDB Explorer entry for gimp_image_new, which will be used in the example below looks like this:
Name: gimp_image_new Blurb: Creates a new Image with the specified with, height, and type In: INT32 INT32 INT32 Out: IMAGE image The ID of the newly created image width height type The width of the image The height of the image The type of image { RGB (0), GRAY (1), INDEXED (2)
Help: Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp_display_new' with this image as an argument will fail. Layers can be created using the 'gimp_layer_new' commands. They can be added to an image using the 'gimp_image_add_layer' command All the the constants mentioned in the PDB Explorer have been defined within Gimp::Fu and may be used within perl. E.g. I.e. a call to create a new image of size 100x150 of type RGB looks as follows:
$img = gimp_image_new(100, 150, RGB)
The PDB entry above shows that gimp_image_new is called with three parameters width, height, type. These are all of type INT32. This type and other types will be explained below.
Script-Fu scripts are called just like any other script according to the PDB signature in the PDB browser. E.g. to run the Script Fu basic one logo just do:
script_fu_basic1_logo("Hello", 72, "-*-utopia-*-r-*-*-72-*-*-*-*-*-*-*", [0,0,0],[1,1,1]);
Unfortunately, as of the writing, calling Script Fu from perl has proved a to make both ScriptFu and gimp very unstable and caused both of them to crash. If any of the readers is able to describe what is needed to get it to run successfully, I will happily include this in a future version of this tutorial.
Note!
When calling a PDB function from Perl::Gimp that has an image and a drawable as the two first arguments, only the drawable should be given as argument in the calling sequence.
4.1. Gimp::Fu and the register function Gimp-Fu is perl's answer to Script-Fu. It provides a simplified method for accepting parameters for a script through a Gtk interface, just like script-fu, but as we shall see below, it has some additional bells and whistles.
The main function for a Gimp-Fu script is the register function. This function declares the interface of the script to gimp. The register function takes the following 10 parameters, that must all be provided:
1. The name of the function - a string. This is the name of the function as it will be known in the PDB. 2. A small description - a string 3. A help text - a string 4. The authors name - a string 5. The copyright of the script - a string 6. Creation date - a string 7. Menu path - a string. The path has one of the two forms: 1. "<Toolbox>/Xtns/Perl-Fu/Script Name" 2. "<Image>/Perl-Fu/Script Name" If form 1. is given, then the script is a standalone script that appears in the menu hierarchy under Xtns/Perl-Fu and takes all its inputs through the Gimp::Fu interface frame. If form 2. is given on the other hand, then the script is tied to the image menu popped up through the right hand button over any image. In this case Gimp::Fu will add as the first two parameters to the script the image and the drawable active when the script was invoked. 8. The acceptable image types - a string. This list contains a list of image types acceptable. This field is only used for scripts that are in the "<Image>" hieararchy. Possible values are listed in the table below: value * meaning Any images are accepted
RGB RGB images RGBA RGB images with alpha channels GREY Grey level images
9. Parameters - A reference to an array of parameters. (A reference to an array in perl is simply an array written within square brackets). Each parameter in turn is a reference to an array containg the following four or five values: 1. The type of the parameter. The types recognized by Gimp::Fu and their perl are given in the following table: Type PF_INT PF_INT32 PF_INT16 PF_INT8 PF_VALUE PF_FLOAT PF_TOGGLE PF_BOOLEAN PF_SLIDER PF_SPINNER 42 Possible forms Comment A number. PF_INT is a synonym to PF_INT32.
3.141
0 1 An integer value through a slider and a spinner interface. The range parameter should be specified and is interpreted as minimum, maximum, and step, e.g. [0,100,1].
A boolean value.
PF_FONT
-*-blippo-*-*-*-*-24-*-*- A font in X11 font format. This interface *-*-*-*-* launches a font browser. "A string" [255,127,0]
#ff7f00
A string A color may either be expressed as a reference to an array of three components, or as a hexadecimal triple, proceeded by the hash sign. A boolean toggle
PF_TOGGLE
0 1 -
PF_PATTERN
A pattern
2. The name of the parameter - a string 3. A help text for the parameter 4. Default value for the parameter. This should be given in the form listed in the table above. 5. An array defining allowed range for the value. This is only possible for PF_SLIDER and PF_SPINNER. 10. A reference to an array of return types of the sub in the 11th parameter. 11. The sub to be called - a reference to a sub . This subroutine will be called when the associated menu entry declared through the Menu path described above. When the sub is called it is passed as arguments the list of parameters declared in field 9, declared above, and in the case of a "<Image>..." script, the active image and layer as first and second parameters.
A reference to a sub in perl may be declared in two ways. Either by declaring a subroutine at a different place in the source file, e.g. sub run and reference it by writing \&run. An alternative way is to write it inline by simply writing:
sub { ($text, $color) = @_ ; ... }
The sub is expected not need to display a new image after it has created it. Instead it is expected to return the new image or images that were created in accordance with the return types declared in parameter 10 of the register call described above. This behaviour has been added in order to be able to call the sub noninteractively. More about that behaviour below. 4.2. A commented script The following Gimp::Fu script example shows the steps described in the previous section. It registeres a script that takes two values, the size of the image and a color, and then produces an image of the requested size with the requested color. Quite useless, but is shows the importent steps of how to register a script, how to create a new image, and how to access some PDB functions. uni
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: #!/usr/local/bin/perl -w use Gimp ":auto"; use Gimp::Fu; sub img_uni { my ($size, $color) = @_; # Create a new image $img = gimp_image_new($size, $size, RGB); # Create a new layer $layer = gimp_layer_new($img, $size, $size, RGB, "Layer 1", 100, NORMAL_MODE); # add the layer to the image gimp_image_add_layer($img, $layer, -1); # Set the background to the required color gimp_palette_set_background($color);
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
# Paint the layer gimp_edit_fill($layer, BG_IMAGE_FILL); # Return the image return $img; } register "img_uni", # fill in name "Create a uniform image", # a small description "A tutorial script", # a help text "Dov Grobgeld", # Your name "Dov Grobgeld (c)", # Your copyright "1999-05-14", # Date "<Toolbox>/Xtns/Perl-Fu/Tutorial/Img Uni", # menu path "*", # Image types [ [PF_INT, "size", "Img size", 100], [PF_COLOR, "color", "Img color", [255,127,0]] ], \&img_uni; exit main();
Most of these commands are directly copied out the PDB. This script shows the essential steps of producing a stand-alone script:
line(s) 10 Description Creating a new image.
13-14 Creating one or more layers. 17 Attaching the layer to the image.
19-23 Do some painting operations in the layers. 26 Return the image to the caller
29-42 Registration of the extension To test the script, save it in the directory $HOME/.gimp-1.2/plug-ins. It must then be made executable through the command:
chmod +x $HOME/.gimp-1.2/plug-ins/uni
Then start gimp. It is generally a good idea to test the syntax of the script with perl -c before starting gimp. (A more official way to add scripts is to use the gimptool --install-bin command).
Note: Due to a bug in gimp (verified for version 1.2) it is not possible to add scripts once gimp is running. On the other hand, it is possible to change a script which has already been registered, as long as the parameters don't change. The script is now accessible through the menu system through the Xtns top menu:
When choosing this menu entry the following screen is popped up:
procedural syntax
The substitution rule for converting a PDB turning into a method is as simple as erasing ``gimp_image_'' from the beginning of the function call and calling this method through the image object. Similarly for the gimp_drawable_... functions. Note that the object oriented syntax is only syntactic sugar that makes the calling syntax cleaner in some cases. The error messages are still given in the procedural format.
Help: This procedure fills the specified drawable with the fill mode. If the fill mode is foreground, the current foreground color is used. If the fill mode is background, the current background color is used. Other fill modes should not be used. This procedure only affects regions within a selection if there is a selection active.
Thus, if a selection is active when gimp_edit_fill is called only the selection is painted. There are lots of ways of choosing a selection as can be seen when searching for a ``select'' in the PDB. The example below uses gimp_rect_select, whose entry in the PDB looks as follows:
Name: gimp_rect_select Blurb: Create a rectangular selection over the specified image In: IMAGE FLOAT image x The image x coordinate of upper-left corner of rectangle
y coordinate of upper-left corner of rectangle the width of the rectangle: width > 0 the height of the rectangle: width > 0 the selection operation: {ADD (0), SUB(1), REPLACE (2), INTERSECT (3) } feather option for selections radius for feather operation
INT32 FLOAT
feather feather_radius
Help: This tool creates a rectangular selection over the specified image. The rectangular region can be either added to, subtracted from, or replace the contents of the previous selection mask. If the feather option is enabled, the resulting selection is blurred before combining. The blur is a gaussian blur with the specified feather radius. A simple use of this function which selects a rectangle in the middle of an image and paints that rectangle with a user defined color. This example also introduces a couple of new features we haven't seen before: The script is associated with an image since its menu path starts with "<Image>/...". Note that as a result of this the callback sub in line 13 receives two additional parameters, the active image and the seleced drawable. The use of a subroutine without a name as a parameter to register The use of the PDB functions gimp_undo_push_group_start and gimp_undo_push_group_end. These functions declare an undo group. When an undo is done on the image, instead of having the individual operators undo, all the actions between the undo start and the undo group calls will be undone at once. The return type of the register function defines what new images should be displayed by gimp. In this case we don't want to display any new images and therefore return an empty array. paint-select
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: #!/usr/local/bin/perl -w use Gimp ":auto"; use Gimp::Fu; register "img_paint_select", "Paints the selection", "Paints the selection", "Dov Grobgeld", "Dov Grobgeld", "1999-05-14", "<Image>/Perl-Fu/Tutorial/Paint Select", "*", [ [PF_COLOR, "color", "Rectangle color", [0,0,255]] ], sub { my($img, $layer, $color) = @_; my($width, $height) = (gimp_image_width($img), gimp_image_height($img)); # Select a rectangle inside the image and paint it with color
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
gimp_undo_push_group_start($img); gimp_rect_select($img, $width/4, $height/4, $width/2, $height/2, REPLACE, 0,0); gimp_palette_set_background($color); gimp_edit_fill($layer, BG_IMAGE_FILL); gimp_selection_none($img); gimp_displays_flush(); gimp_undo_push_group_end($img); # Tell gimp not to display a new image return (); }; exit main();
6.1. Complex selections Besides rectangular selections elliptical selections may also be created through the PDB functions gimp_ellipse_select() and gimp_free_select() which allows the selection of ellipses and polygons.
More complex selections may be created through the channel mechanism. The PDB gimp_channel_new() creates a new channel. The channel is a drawable that may be painted into, just like any other drawable, but with the difference that it is always a grey level image. Once the channel is finished, the channel may be loaded into the selection through the PDB function gimp_selection_load(). Search for ``select'' in the DB Browser to see a list of all the selection related functions.
6.2. Loops In perl it is trivial to write loops that together with the various selecton tools gives powerful creative possibilities. Here is an example that mixes colors in circles. There is nothing really new here, but it shows the power of the what we have described above. circles
1: 2: 3: 4: #!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu;
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
sub circles { my ($size, $bgcolor, $radius) = @_; # Create the background $img = gimp_image_new($size, $size, RGB); $layer = gimp_layer_new($img, $size, $size, RGB, "Layer 1", 100, NORMAL_MODE); gimp_image_add_layer($layer, -1); gimp_palette_set_background($bgcolor); gimp_edit_fill($layer, BG_IMAGE_FILL); my $ncircles = int($size/$radius/2); for ($i=0; $i<$ncircles; $i++) { for ($j=0; $j<$ncircles; $j++) { # Be creative and mix colors $color = [$i*30, ($ncircles-$j)*25, ($i+$j)*15]; # Select a circle gimp_ellipse_select($img, $i*$radius*2, $j*$radius*2, $radius*2, $radius*2, REPLACE, 1, 0, 0); # Paint the color in the circle gimp_palette_set_background($color); gimp_edit_fill($layer, BG_IMAGE_FILL); gimp_selection_none($img); } } return $img; } # register the script register "circles", "a loop", "a loop", "Dov", "Dov", "1999-05-14", "<Toolbox>/Xtns/Perl-Fu/Tutorial/Circles", "*", [ [PF_INT32, "size", "Img size", 100], [PF_COLOR, "bg", "Background color", [40,180,60]], [PF_INT32, "radius", "Circle radius", 10] ], \&circles; exit main();
The result:
7. Creating text
7.1. Hello World - writing text in an image To create text the PDB function gimp_text_fontname() may be used. In this function the font is specified in the X11 font conventions. (There are also some older functions, gimp_text and gimp_text_ext in which the different X11 fields are specified explicitely.)
The result:
The script makes use of the function xlfd_size which extracts the size of the font from the X11 font name. This is necessary as the authors of gimp_text_fontname decided that the font size within the fontname is ignored.
One thing to note in this script is that the text that is created on line 24 is a floating layer, than needs to be anchored to its parent layer. This is done in line 27 through the call to gimp_floating_sel_anchor(). This script suffers from the problem that the image size is unrelated to the text size. This is taken care of in the following more complex example which shows the basic steps for a logo generating script.
Creation of an image arbitrary size Creation of a background drawable of an arbitrary size Creation of text layer which exactly fits the text with the command gimp_text_fontname(). Resizing the image and the background to the size of the text layer. The result is an image composed of two layers; a transparent text layer on top of a uniform background. basic-logo
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: #!/usr/local/bin/perl use Gimp ":auto"; use Gimp::Fu; sub basic_logo { my($font, $border, $text, $bgcolor, $fgcolor) = @_; # Create a new image of an arbitrary size with $img = gimp_image_new(100, 100, RGB); # Create a new layer for the background of arbitrary size, and # add it to the image my $background = gimp_layer_new($img, 100, 100, RGB, "Background", 100, NORMAL_MODE); gimp_image_add_layer($background, 1); # Choose color of text gimp_palette_set_foreground($fgcolor);
21: 22: # Create the text layer. Using -1 as the drawable creates a new layer. 23: my $text_layer = gimp_text_fontname($img, -1, 0, 0, $text, 24: $border, 1, xlfd_size($font), $font); 25: 26: # Get size of the text drawable and resize the image and the 27: # background layer to this size. 28: my($width, $height) = ($text_layer->width, $text_layer->height); 29: gimp_image_resize($img, $width, $height, 0, 0); 30: gimp_layer_resize($background, $width, $height, 0, 0); 31: 32: # Fill the background layer now when it has the right size. 33: gimp_palette_set_background($bgcolor); 34: gimp_edit_fill($background, BG_IMAGE_FILL); 35: 36: return $img; 37: } 38: 39: # register the script 40: register "basic_logo", "basic logo", "basic logo", 41: "Dov Grobgeld", "Dov Grobgeld", 42: "1999-06-09", 43: "<Toolbox>/Xtns/Perl-Fu/Tutorial/Basic Logo", 44: "*", 45: [ 46: [PF_FONT, "font", "font", "-*-utopia-bold-r-*-*-70-*-*-**-*-*-*"], 47: [PF_INT, "border", "border", "10"], 48: [PF_STRING, "text", "text", "Hello world!"], 49: [PF_COLOR, "bg_color", "Background color", [40,180,160]], 50: [PF_COLOR, "fg_color", "Background color", [255,255,0]], 51: ], 52: \&basic_logo; 53: 54: # Handle over control to gimp 55: exit main();
Note the special syntax of gimp_image_text_fontname() in line 23 in basiclogo with an image specified for a first parameter, and the drawable = -1. This is in contradiction to the rule above that the image should not be specified for PDB functions that take both an image and a drawable as the first two parameters. But since the drawable=-1, which has no image related to it, an image explicitely be provided. The special case drawable=-1 means that instead of creating a floating layer, a new image layer will be created. The result shown in the following dialog and the resulting image:
8. Floating selections
When a region has been selected through one of the selection routines the area outlined by the selection may be copied to the cut-buffer through the gimp_edit_copy command. The cut-buffer may subsequently be pasted into a different layer through the gimp_edit_paste command. When a layer is pasted it becomes a floating selection. This floating selection may be moved to its required position by the command gimp_layer_set_offsets, and finally it is pasted by the gimp_floating_sel_anchor command. Another way of determining the position of a pasted layer is to create a selection in the target image before the cut-buffer is pasted.
This is illustrated in the following program, which works on one image and takes as a parameter an another image, which it concatinates to the right of the first image. The lines 28-38 shows how the second image is copied and glued into the first image.
horiz-cat
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: #!/usr/local/bin/perl use Gimp qw( :auto ); use Gimp::Fu; sub horiz_cat { my($img1, $drw1, $drw2) = @_; # Get image 2 $img1 = $drw1->image();
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
my $img2 = gimp_drawable_image($drw2); my($w1, $h1) = ($drw1->width, $drw1->height); my($w2, $h2) = ($drw2->width, $drw2->height); # The new height is the maximum height of the images my $hmax = $h1 > $h2 ? $h1 : $h2; # Create an undo group gimp_undo_push_group_start($img1); # Resize the drawable layer to make room for the img gimp_image_resize($img1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2); gimp_layer_resize($drw1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2); # Copy $drawable2 and paste it into the new space of $drawable1 # select all of img2 $img2->selection_all(); $drw2->edit_copy(); # make a selection in img 1 where $drw2 is to be pasted gimp_rect_select($img1, $w1, ($hmax-$h2)/2, $w2, $h2, 0,0,0); # paste and then anchor it my $floating_layer = gimp_edit_paste($drw1, 0); gimp_floating_sel_anchor($floating_layer); # Close the undo group gimp_undo_push_group_end($img1); # Update the display gimp_displays_flush(); return undef; } # register the script register "horiz_cat", "Horizontal concat", "Horizontal Concat", "Dov Grobgeld", "Dov Grobgeld", "2003-05-04", "<Image>/Perl-Fu/Tutorial/Horizontal Concat", "*", [[PF_DRAWABLE, "drawable", "Drawable to concatinate", undef]], \&horiz_cat; exit main();
When a perl-fu script is run from the command line, the result is the same as when it is run through the menus, except of the fact that it may be run with the --
output
parameter in case it will save the result to a file instead of displaying it within gimp. This is great for batch creation of logos, etc. The filename for the --output has some special magic that allows to set some special image saving parameters, like interlace, quality factor, etc. See the Gimp::Fu man page for details. Note that the normal rules about image and file types are still valid, thus e.g. in order to save an image as a gif file, it must be converted from RGB to an indexed script. Currently this functionality must be included in each script, but it is possible that a future version of Gimp::Fu, includes this conversion as an option. Here are two invocations of the scripts declared above, but with output written to a jpg file and a png file. As we said above, we can't save them as gif as the scripts do not index the images.
perl-gimp-from-shell
1: 2: 3: uni -o /tmp/uni.ppm -size 100 -color "#5050ff" basic-logo -font '-*-utopia-*-r-*-*-100-*-*-*-*-*-*-*' -o /tmp/bl.ppm -text "Perl rules"
Note that due to a bug in my version of Gimp/Perl I was not able to output images in any format but in ppm and gif. Your milage may vary. Another importent use of this interface is that it enables running the perl debugger on the perl-fu scripts. Note: The image is saved to the directory where gimp was started from and not to the directory in which the scripts were invoked, unless a complete path is given!
9.1. A shell for gimp-perl When using the perl-server it is not necessary to use Gimp::Fu and the register function. Instead a sub named on_net may be declared, which points to a routine that will be called when gimp starts.
For a simple but powerful example of the use of the Gimp without Fu, here is a an interactive perl gimp shell that may be run from the command line:
pg-shell
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: #!/usr/local/bin/perl ###################################################################### # An interactive command line shell to gimp. ###################################################################### use Gimp ":auto"; use Term::ReadLine; sub interact { $term = new Term::ReadLine("Gimp"); while( defined ($_ = $term->readline("Gimp> "))) { $res = eval($_) . "\n"; print("Error: $@"), next if $@; print "\n"; gimp_displays_flush();
PERL DEBUGGED
Text and images Copyright (C) 2002 Seth Burgess and may not be used without permission of the author.
Intention
The Perl module for GIMP is a nice evolution of the scripting interface of GIMP. It removes the dependence on the relatively rarely encountered scheme language of script-fu and replaces it with one that is familiar to a much larger audience. In doing so, the perl interface to GIMP also can take advantage of many of the features that have been added to perl over the years. My aim in creating this tutorial is to make debugging scripts easier. We'll touch on the facilities provided by the Gimp module, and then focus on using the perl debugger to interactively develop scripts. To illustrate the points in this tutorial, this is a simple script that will change as we progress:
#!/usr/bin/perl
register "example", "Example", "Dumb example for debugging", "Seth Burgess", "Seth Burgess ", "1.0", "/Xtns/Dumb Example", "*", [], sub {
return(); };
exit main;
Gimp::set_trace
The Gimp module provides tracing ability, which is a form of debugging. To activate this, start GIMP from an XTerm, and place the following at the top of the script:
#!/usr/bin/perl
Gimp::set_trace(TRACE_ALL);
register "example", "Example", "Dumb example for debugging", "Seth Burgess", "Seth Burgess ", "1.0", "/Xtns/Dumb Example", "*", [], sub {
return(); };
exit main;
This will give the maximum amount of tracing information, displayed on the console window you start GIMP from. You can cut back on what all gets displayed by using an "or'ed" combination of the following other options in place of TRACE_ALL:
TRACE_NONE
TRACE_CALL
trace only GIMP Procedural Database (PDB) calls (including arguments and return values)
TRACE_TYPE
TRACE_NAME
TRACE_DESC
Using TRACE_ALL can let you see easily what parameters are wrong so you can fix misbehaviour in scripts. It provides a powerful history of what could be going wrong in your script.
Perl Debugger
Perl comes with a debugger built in, which we can effectively utilize for interactive execution of our scripts. To invoke this, put a -d on the invocation line for the script as follows:
#!/usr/bin/perl -d
use Gimp qw(:auto); use Gimp::Fu; use Gimp::Util; # Gimp::set_trace(TRACE_ALL); # uncomment to do tracing
register "example", "Example", "Dumb example for debugging", "Seth Burgess", "Seth Burgess <sjburges\@gimp.org>, "1.0", "/Xtns/Dumb Example", "*", [], sub {
return(); };
exit main;
If you change a Gimp-Perl script to utilize this, you'll notice GIMP halting on startup. This is because GIMP is querying the plug-in, and it is halting due to having debugging enabled. Just type 'c' in the window, and then 'q' to let GIMP continue loading:
main::(/home/seth/.gimp-1.3/plug-ins/demo:21): 21: };
use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<1> q
This is not a part of the script we're really intrested in - its the registration of the plug-in with GIMP. It turns out to be a really annoying behaviour, since every time we modify the script we'll need to do this on startup. Luckily we have another way of attacking this provided by the Gimp module - that is the Perl Server. First, move your script out of your plug-ins directory to somewhere else. Then startup GIMP. Start the Perl Server by going to Xtns -> Perl Server. You'll see something like the following in the XTerm window of GIMP:
Now from another XTerm, execute the script (just type its name). This will immediately start debugging the new script. You can set a breakpoint on a line of your choice and execute 'c' to let it execute until that line.
You can now examine variables with perl functions (print $fname) and modify them during runtime. You can change the point of execution, and do most everything you'd expect from a debugger.
$DB::single
Instead of having to remember what line the intresting part of your script starts on and set a breakpoint there, perl provides a way to programmatically jump into single-step mode. Add the following to the top of your sub:
#!/usr/bin/perl -d
use Gimp qw(:auto); use Gimp::Fu; use Gimp::Util; # Gimp::set_trace(TRACE_ALL); # uncomment to do tracing
register "example", "Example", "Dumb example for debugging", "Seth Burgess", "Seth Burgess <sjburges\@gimp.org>", "1.0", "/Xtns/Dumb Example", "*", [], sub {
return(); };
exit main;
Now when you run your script, hit 'c' and it will break on the entry of the sub {} call. Using $DB::single will only have any effect when using -d - its ignored otherwise, so you can leave it in scripts without any side effects.
Example Session
After invoking the perl server, I run 'Example' from a commandline shell:
main::(./Example:20): DB<1> c
};
DB<3> print $fname /home/seth/foo.png DB<4> n main::CODE(0x83f240c)(./Example:17): 17: DB<4> n main::CODE(0x83f240c)(./Example:19): 19: DB<4> c Debugged program terminated. Use q to quit or R to restart, return(); $img->display_new();
use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<4> q
This example session shows changing a value of a variable at run-time so to load a different file than the one hard-coded into the script. Note that I continue ('c') and it stops immediately after $DB::single is set. Far more complex debugging is possible, but this should give you a good taste of what its all about.
Conclusion
Thats all there is to it! I hope this has been useful to you.
You can download a compressed copy of this tutorial. You can also get a copy of the script. Feel free to use either/both however you want. This tutorial has gone over the basics of using the Gimp module for tracing, the Perl Server for starting your scripts, and using the perl debugger to interactively execute your scripts. If you have comments, questions, or suggestions about this tutorial, please drop me a line. Happy GIMPing, Seth The original tutorial can be found here.
Options: -?, --help -v, --version --verbose -d, --no-data patterns, ... -f, --no-fonts Show help options Show version information and exit Be more verbose Do not load brushes, gradients, palettes,
-i, --no-interface
--batch-interpreter=<procedure> The procedure to process batch commands with -b, --batch=<commands> times) ... Batch command to run (can be used multiple
In order to do image processing from the command-line, you usually use the Script-Fu batch interpreter. This is the default, which makes things simple. To give you an impression of what can be done, try the interactive console mode:
gimp -b -
This will tell GIMP to start in batch mode and accept commands on the command-line. This is essentially the same as using the Script-Fu console. It would however be tedious to enter the commands here, so instead we will create a simple script and show you how to run that:
A simple example
(define (simple-unsharp-mask filename radius amount threshold) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable radius amount threshold) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)))
This simple script takes a filename and some numeric parameters. It opens the respective file, applies the Unsharp Mask filter and saves the image again (be careful, for the sake of simplicity this script overwrites the original image). It does all this w/o any user interaction, so we can run it without any user interface. In order to do that, save the script with the .scm extension in the ~/.gimp-2.4/scripts directory. Then run it like this:
There is a catch here: Some plugins or Script-Fu scripts create new layers and then flatten the image again. This changes the drawable ID. If this is the case insert the following line to get the current drawable ID just before saving the image:
(define (batch-unsharp-mask pattern radius amount threshold) (let* ((filelist (cadr (file-glob pattern 1)))) (while (not (null? filelist)) (let* ((filename (car filelist)) (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug-in-unsharp-mask RUN-NONINTERACTIVE
image drawable radius amount threshold) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)) (set! filelist (cdr filelist)))))
This version of the script takes a glob pattern instead of a filename and will apply the Unsharp Mask filter to all files matching this pattern. In order to sharpen all PNG images in the current directory, you would run the following command:
Further information
If you want to write your own scripts for batch processing, we suggest you use the Procedure Browser as found in the Xtns menu in the GIMP toolbox. It gives you a detailed list of all commands.
BASIC SCHEME
Text and images Copyright (C) 2002 Dov Grobgeld and may not be used without permission of the author. Editor's note: since this tutorial was published, the old GIMP Script-Fu interpreter (SIOD) has been replaced by a newer and better one (TinyScheme). A Script-Fu migration guide is available.
Intention
One of the wonderful features of GIMP is that it all its functionality may be accessed through scripting. The major scripting language for GIMP that has been attached to it today is Scheme.
This document will try to be a brief introduction to Scheme, just teaching the essentials in order to write Script-Fu scripts, without getting into the programming language theory that is so typical of other Scheme references.
1. Expressions
Scheme is a Lisp variant and all expressions are surrounded by parentheses. E.g. a list which will calculate the sum of 3 and 4 is written
(+ 3 4)
The + sign is the addition function and 3 and 4 are the first and second parameters to this function. Expressions may be nested, so the expression (3+4)*(5/6) would in Scheme be written
(* (+ 3 4) (/ 5 6))
White space has no importance so the above expression may as well be written:
(* (+ 3 4) (/ 5 6))
2. Functions
Aside from the four arithmetic functions that are represented through the symbols + - * / there are lots of other functions built into the language. All of them have the form
Additional functions may be defined by the user through the define keyword. E.g. a function that calculates the square value of its single argument may be declared like this
(square 5)
Lisp and its variants make heavy use of lists. Script-Fu is no exception and it uses e.g. a list of three elements to write a RGB color. E.g. the color orange would be written
'(255 127 0)
The ' sign is necessary in order to tell Scheme that this is a literal list. If the ' was omitted Scheme would try to look up a function with the name 255 and send it the two parameters 127 and 0, which is obviously not what we want. To create a variable called orange with the above value and then set the background color to it we may do
[The following is a test of the above functions which may be interactively conducted in the Script-Fu console.]
=> (set! color '(255 127 63)) (255 127 63) => (car color) 255 => (cdr color) (127 63)
To get the blue component of a color it is necessary to apply the cdr function twice and then the car function.
This is very inconvenient to write. Therefore there have been defined abreviations of the form cadr, cddr, caddr, etc that concatenate the operations described above. The previous expression may therefore be much more conveniently written:
For the Script-Fu writer one of the most important uses of the car function is to access the returned values from the built-in GIMP functions. All gimp-functions return a list, and even if the list contains only one element it must be accessed by car. This is e.g. the case for the important functions gimp-new-image and gimp-new-layer used below.
Here a and b have a local scope and retain their values only up to the closing paren matching the one before let* .
produces a new GIMP image of type RGB and size 100x150. All the functions of the PDB may be accessed through the Procedure Browser that is available from the main menu through Xtns ->Procedure Browser.... E.g. the Procedure Browser entry for uni-img, which we will define in the example below looks like this:
For the Script-Fu programmer this information shows that uni-img may be called with three parameters of the types INT32, STRING and COLOR. The different types will be explained below.
The last point above actually means that a script is from Gimp's viewpoint in no way different from a built-in command or a plugin command. As long as a command is registered in the PDB it can be called by any script or plugin. The parameters of script-fu-register may be divided into two groups. The first group of seven parameters must always be given. These are: 1. 2. 3. 4. 5. 6. 7. The name of the function. The name of the script to be used as a menu entry. A help string describing the function of the script. The script author. The script copyright. Script date. List of valid image types for the script. This only has a meaning on scripts operating on images that already exist. After these seven parameters have been given, a list of the parameters required by the script follows. Each parameter is given as a group of three items: 1. The type of the parameter. Some of the valid types are:
SF-IMAGE
SFDRAWABL E 2. 3. A label for Script-Fu to display when querying for the parameter. A default value.
6. A commented script
The following script uni.scm receives two parameters from the user, the size of the image and a color, and goes on to produce a uniform image of the requested size and the requested color. Not very useful, but it shows the essential steps in producing a Script-Fu script.
; Define the function of the script and list its parameters ; The parameters will be matched with the parameters listed ; below in script-fu-register.
(define (uni-img size color) ; Create an img and a layer (set! img (car (gimp-image-new size size RGB))) (set! layer (car (gimp-layer-new img size size RGB "layer 1" 100 NORMAL)))
; The following is done for all scripts (gimp-image-undo-disable img) (gimp-image-add-layer img layer 0)
; and layer and may paint in the layer through the PDB functions. (gimp-palette-set-background color) (gimp-edit-fill layer BG-IMAGE-FILL)
; The following is also done for all script (gimp-display-new img) (gimp-image-undo-enable img))
; Finally register our script with script-fu. (script-fu-register "uni-img" "Uniform image" "Creates a uniform image" "Dov Grobgeld <dov@imagic.weizmann.ac.il>" "Dov Grobgeld" "2002-02-12" "" SF-VALUE "size" "100" SF-COLOR "color" '(255 127 0)) (script-fu-menu-register "uni-img" "<Toolbox>/Xtns/ScriptFu/Tutorials")
To test the script save it in $HOME/.gimp-2.2/scripts/uni.scm and then select Xtns -> Script-Fu > Refresh:
The script Uniform image should now appear in the pulldown menu Xtns -> Script-Fu -> Tutorials -> Uniform image. Selecting this script results in the following popup:
Accepting these default parameters through the OK button gives us the following new image:
It is also possible to access this script through the Script-Fu console by typing the command
; An example script that blurs an image according to a blur radius. ; It illustrates how to hang a script in the image menu, and ; how a plug-in may be called.
(script-fu-register "script-fu-copy-blur" "Copy and Blur" "Copy and blur a layer" "Dov Grobgeld" "Dov Grobgeld" "2002" "RGB*, GRAY*" SF-IMAGE "Image" 0
Name:
gimp-edit-fill
Blurb:
In:
DRAWABLE
drawable
INT32
fill_type
The type of fill: FG-IMAGE-FILL (0), BG-IMAGE-FILL (1), WHITE-IMAGE-FILL (2), TRANS-IMAGE-FILL (3), NOIMAGE-FILL (4)
Help:
This procedure fills the specified drawable with the fill mode. If the fill mode is foreground, the current foreground color is used. If the fill mode is background, the current background color is used. Other fill modes should not be used. This procedure only affects regions within a selection if there is a selection active.
Thus, if we have a selection active when gimp-edit-fill is called, then only the selection is painted. There are lots of ways of choosing a selection as can be seen when searching for a ``select'' in the PDB. We will use gimp-rect-select, whose entry in the PDB looks as follows:
Name:
gimp-rect-select
Blurb:
In:
IMAGE
image
The image
FLOAT
FLOAT
FLOAT
width
FLOAT
height
INT32
operation
the selection operation: {ADD (0), SUB(1), REPLACE (2), INTERSECT (3) }
INT32
feather
FLOAT
feather_radius
Help:
This tool creates a rectangular selection over the specified image. The rectangular region can be either added to, subtracted from, or replace the contents of the previous selection mask. If the feather option is enabled, the resulting selection is blurred before combining. The blur is a gaussian blur with the specified feather radius.
A simple use of this function which selects the rectangle (x,y,width,height) = (0,25,100,50), paints this region blue, and releases the selection looks as follows:
(gimp-rect-select img 0 25 100 50 REPLACE 0 0) (gimp-palette-set-background '(0 0 255)) (gimp-edit-fill layer BG-IMAGE-FILL)
(gimp-selection-none img)
8. Loops
The only looping construct that exists in Script-Fu is while [Note: this constraint is due to the current Scheme interpreter SIOD used for Script-Fu.] The while loop looks as follows:
(set! y 0) (while (< y size) (gimp-rect-select img 0 y size 16 REPLACE 0 0) (gimp-edit-fill layer-one BG-IMAGE-FILL) (set! y (+ y 32)))
9. Floating selections
When pasting an image from the clipboard, or when creating text in a a drawable, the result is not put directly in the drawable. Instead it is put into a special temporary layer known as a floating selection. The floating selection may be manipulated in several ways, and finally it is merged into its associated layer, a process known as anchoring.
When creating text through the gimp-text command, the text is always put into a temporary layer. This temporary layer then has to be anchored. Here is an example of creating some text which is pasted into the current drawable:
; An example script that writes a fixed string in the current ; image. (define (script-fu-hello-world img drawable)
; Start an undo group. Everything between the start and the end will ; be carried out if an undo command is issued. (gimp-undo-push-group-start img)
; Create the text. See the Procedure Browser for parameters of gimp-text. (set! text-float (car (gimp-text-fontname img drawable 10 10 "Hello world" 0 1 50 0 "Sans")))
(script-fu-register "script-fu-hello-world"
"Hello World" "Write Hello World in the current image" "Dov Grobgeld <dov@imagic.weizmann.ac.il>" "Dov Grobgeld" "2002-02-12" "RGB*, GRAY*" SF-IMAGE "Input Image" 0 SF-DRAWABLE "Input Drawable" 0) (script-fu-menu-register "script-fu-hello-world" "<Image>/Script-Fu/Tutorials")
This script shows another feature we haven't mentioned before. The possibility of creating an undo group. All the commands between the commands gimp-undo-push-group-begin and gimp-undo-push-group-end are undone together if the undo command is issued.
; An example of how to create a floating layer and how to ancor it. (define (script-fu-sel-copy img drawable)
(gimp-undo-push-group-start img) (gimp-edit-copy drawable) (set! sel-float (car (gimp-edit-paste drawable FALSE)))
(script-fu-register "script-fu-sel-copy" "Selection Copy" "Copy the selection into the same layer" "Dov Grobgeld" "Dov Grobgeld" "2002-02-12" "RGB*, GRAY*" SF-IMAGE "Image" 0 SF-DRAWABLE "Layer" 0) (script-fu-menu-register "script-fu-sel-copy" "<Image>/Script-Fu/Tutorials")
BASIC SCHEME2
This article was originally published in Linux Magazine, January 2002. Editor's note: since this tutorial was published, the old GIMP Script-Fu interpreter (SIOD) has been replaced by a newer and better one (TinyScheme). A Script-Fu migration guide is available.
Intention
Unix (and by association, GNU/Linux) provides the user with an environment full of possibilities. To turn these possibilities into reality, a Unix user must be technical in two senses of the word. Of course, he must understand technology, but to really shine, he must understand and even appreciate good technique. Unix is filled with tools that, through an unspoken yet common understanding of the Unix Philosophy, work well with each other. To the creative user who can interconnect and combine these powerful tools, Unix can be very rewarding. With that in mind, welcome to our Power Tools column. Our goal here is to help you discover different ways to get the most out of all the useful software that is out there, and to demonstrate how powerful these tools can really be in the hands of a skillful and technical user. We begin this month with a look at GIMP. One of GIMP's strong points has always been its scriptability. In fact, it's widely acknowledged to be one of the cooler features of GIMP. But when it comes right down to it, there really are not that many people who can honestly say, "I know Script-Fu." Part of the problem is Scheme, the language used to write scripts for GIMP. It is a Lisp-like language that looks funny compared to most mainstream languages, and that's enough to dissuade a lot of people from trying it. For anyone who really wants to learn Scheme, though, GIMP is a good place to start, because you'll be able to achieve useful results relatively quickly due to the richness of its programming interface. Sometimes it's a little too rich, though. The other problem is that the API for GIMP can seem overwhelmingly large at times. Fortunately, there's a way to break down this formidable API into something that is actually comprehensible by mere mortals. But we'll get to that in a minute. First, let's take a look at a very small subset of Scheme.
Scheme has a simple and uniform syntax compared to most other languages, but there's still no way to properly explain it in this limited space. With that in mind, we'll cover the bare minimum of Scheme that you'll need to get started with GIMP scripting. Fortunately, it's true that a little knowledge can go a long way, so if you don't know Scheme, read on. The first thing people notice when they look at Scheme is all the nested parentheses. Whatever you do, don't panic. There's a very simple concept behind this, and chances are good that you already understand it. Semantically, it's not that different from HTML. For example, the following:
<ul><li><b>bold</b></li><li><i>italic</i></li></ul>
Each matching pair of parentheses forms what is called an s-expression. The "s" stands for "symbolic," because s-expressions usually contain symbolic information (like function and variable names) inside them. Literal information (like strings or numbers) is represented in the usual way -- numbers are written in decimal notation, and strings are surrounded by a set of double quotes, like "bold" is in the example. An s-expression can also contain other sexpressions nested within it, making it a good notation for storing data as well as writing code. When you are using s-expressions to represent code, the first item represents the function you want to use, and everything after it is considered a parameter of the function. What surprises many people is that in Scheme, nearly everything is done with a function. Even for basic math, what would be:
5 + 9 / 3
(+ 5 (/ 9 3))
This may take a little getting used to. First, the order of things may look strange. If you're used to "infix notation" (i.e., the way the first equation is written -- with the operands being separated by the operators), then training yourself to use "prefix notation" (the way the second equation is written -- with the operators placed before the operands) might take a little practice. Don't worry -- it's not as unsettling as it looks once you get the hang of it.
Beyond our simple arithmetic example above, there are two functions in Scheme that you will need to know to help you understand the latter half of this article. set!: This is the equivalent of the = (or assignment) operator which is seen in most other languages. Its purpose is simply to assign a given value to a particular variable. For example, the following assigns 5 to the variable a and the list of numbers (1 2 3) to b.
Note that the single-quote before the (1 2 3) is very important. It tells Scheme that the following s-expression is actually data and not code. Without the single-quote, the Scheme interpreter would have tried to treat the 1 as a function and failed miserably. car: An s-expression is a list of things, but this is no ordinary list. In Scheme, lists are composed of only two things -- a head, which is the first item in the list, and a tail, which is everything else (and which is also a list). car is the function used to grab the head of a list. For example, (car '(3 2 1)) returns 3. This is very useful, because functions in the GIMP API almost always return lists; even when only one thing is returned, it's returned in a one-element list, so it's necessary to know this basic list operation. This is barely a scratch on the surface of what Scheme provides, but it's enough for now. There are already many good Scheme tutorials out there anyway, so why not make the most of them? You can take a look at Resources for more information.
Figure One: The five constructor functions are listed in the top left of the window. These five functions are constructors for the five objects that the entire GIMP API revolves around. If you can understand exactly what each of these objects represents, then you are well on your way to being able to script GIMP. Let's get started by instantiating some of these objects. Be sure to get a Script-Fu console from (Xtns -> Script-Fu -> Console) so that there is a place for you to type in Scheme code. Now, let's start by following along with Listing One.
; images need layers (set! layer (car (gimp-layer-new image 320 240 RGB_IMAGE "layer" (gimp-image-add-layer image layer -1) 100.0 0)))
; let's draw (set! points (cons-array 4 'double)) (aset points 0 0) (aset points 1 0) (aset points 2 320) ; (x1, y1) (aset points 3 240) (gimp-palette-set-foreground '(255 0 0)) (gimp-paintbrush-default layer 4 points) ; (x0, y0)
Image: The most important object in GIMP is the Image object, without which there would be no "I" in "GIMP." On line 2, a 320x240 pixel, RGB image is instantiated and assigned to image. GIMP has an abstract concept of what an Image object is. Aside from having properties like width and height, an image can be thought of as a collection of Layer objects. Layer: Layers are very important because without them, there would be nothing to draw on. On lines 5 through 9, a Layer object is instantiated and then layer is added to image. Channel: The purpose of channels is to provide a selective view of the coloration of an image. For instance, all RGB images come with a red, green, and blue channel. If you wanted to affect only the "blueness" of an image, you could disable the red and green channels and only draw on the blue channel. It's a useful but rather advanced concept, so we'll skip this one for now. Display: Although not strictly required, it would be nice to be able to watch our image as graphics are being drawn on it. To do this, a Display object is opened on line 12. Our layer might be filled with garbage, so it's a good idea to use the gimp-edit-clear function to ensure that we start with a clean slate. (Hopefully, the layer constructor will behave more consistently in the future.) Note that as you write Scheme code into the Script-Fu Console, changes in the image will show up interactively. Drawable: In C++ terminology, a Drawable would be an abstract base class which Layer and Channel are subclasses of. As the name implies, drawables are anything that can be drawn on. For example, one can draw on channels to perform advanced color effects. But for now we'll just stick to drawing on a layer.
There are many, many functions in the GIMP API for manipulating drawables. On lines 16 to 22, gimp-paintbrush-default is used to draw a line on layer. Since this function needs an array of (x,y) coordinates, the cons-array function is used to allocate an array of doubles and the aset function is used to fill it with values. Before the line is drawn, we change our default foreground color to a bright red using gimp-palette-set-foreground. If you've typed everything in correctly, you should have something that looks like Figure Two showed below.
Resources
Teach Yourself Scheme in Fixnum Days Mike Terry's Black Belt School of Script-Fu Richard Stallman: The Coder (web archive) Why Functional Programming Matters SIOD Scheme (web archive) This article was originally published in Linux Magazine, January 2002. It has since then seen some minor updates.