Thursday, June 4, 2015

How to hatch an image in GIMP

I posted a similar post but much simpler about my Auto Hatch Layers script on GIMP LEARN forum here --> Hatching an image in GIMP Script

Inside GIMP, you can manually hatch an image by creating a hatch pattern then copying that pattern into the clipboard and simply dragging that pattern onto a selection to fill the selection with that pattern repeatedly.

Or you also manually hatch an image with the help of a script I wrote to help you with the manual process, you'll just have to select the area (you might have reduced the number of colors of your image) maybe of a specific color, and then run the script.  And the script will allow you to specify 2 colors, one is the hatch color, the other is hatch color number 2 or can also be referred to as hatch background (not always, since my script will flip the colors around if your hatch width percentage is greater than 50%, I did this so that for circles patterns it'll always fit inside a grid of the hatch pattern).   The script will allow you to choose a pattern of "Lines","Squares","Circles","Triangles","Zigzags","Fans","Rings", or "Hollow Squares".
You can specify hatch width percentage so if you want gray 50%, you can specify hatch colors of White and Black and use hatch width percentage of 50%.  So what that will do is it'll give you a hatch pattern that has 50% white over black hatch pattern.
This script is useful if you really want to control every detail of your hatching of your image(s).  You can manually calculate/figure out what color you want but are happy with the 8 built patterns.
Here's the script's options:
 You can specify rotate angle to rotate the hatch pattern to a certain angle (default is 45).  And the hatch Grid Width and Height defines size of hatch square in pixels.  If you make it 5 minimum it'll be a fine hatch, if you make it larger it'll be courser.
Okay enough talk about the script.  You should just download the Hatch Selection Layer script and try it out for yourself.

Now onto something more AUTOMATED!  What if you don't want to do the manual work of defining every color manually? All the simple but tedious math.  Well I wrote a script for that too.
You just have to have an image in RGB mode.
You'll have to select number of colors/hatch you want.  This script will reduce the number of colors of your image down to the number of specified hatches and then automatically hatch your whole image.
Here's the script's options:
You can turn on/off each of the hatch patterns (there's 8 right now) but if none is turned on, it'll default to hatching with "Lines". So for an image of at least 8 colors/hatches you have 255 different ways to choose your Hatch patterns (2^8, 256 but because we don't count the option of having everything turned off).
And you have the option to "Break into color components instead of hatching over black".  What that option does is what it says, it'll try to break your image's color into 2 colors that when combine give the original color so that when possible you have colors other than one of them being black.  If you turn off this option, your hatch pattern will always be a single color over black, if you turn on this option, it'll try to break out Red, Green, or Blue value whichever is the highest out into it's own to be the second color and the other 2 channels combine to give you your first color, unless the highest component cannot be fully represented in the second color then some of that value will be added back to the first color of the hatch so that the combined values of the hatch represents the original color.  There was some really simple but tedious math involved in this when i was writing the script.
"Hatch Start Angle" specifies the start angle of the first hatch pattern.  So if you specify "Hatch Increment Angle For Each Hatch" that is greater than zero.  Each hatch pattern will be incrementally rotating that much starting at the Starting Angle.  If you want all your hatches the same angle, just use zero and they'll all be using "Hatch Start Angle".  And similarly to the manual script above, you can specify the your hatch to be fine or course by chaning the "Hatch Grid Width and Height" (in pixels).
Okay enough talk about the script, You can download the Auto Hatch Layers Script and start playing with it.
To use these scripts: You'll just have to copy the .scm file into your GIMP's Scripts folder and restart GIMP, and they'll be available under Script-Fu/Create New/Auto Hatch Layers Script or Script-Fu/Create New/Hatch Selection Layer depending on which one you're choosing to use.

Here's an example image that I wanted to apply my "Auto Hatch Layers" script on (I just found on the internet, searched for "Snowwhite" images)
And here's the out come when I chose ticked on just "Circles" and "Rings" and specified number of hatches as 30 (so it reduced my image down to 30 colors before it applied the hatches). As you can see the below only have circles and rings pattern.

 Here's a close-up of the above image (just so you can see the hatch patterns easier).

And finally I want to show you some samples of the 8 built hatch patterns (white over black at 50%)
Depending on the percentage, the shapes do shrink to represent that percentage.
Samples of white over black at 50% (click to see details)