ImageSetStyle and ImageSetBrush

This tutorial will show examples of GD functions ImageSetStyle and ImageSetBrush. Like imagesetthickness($image,#), you set your style or your brush after you have defined the style or the brush. You can get some interesting results from these functions but they may not always be what you might expect. The basic idea is to set a pattern of color for your style or brush. One color represents 1 pixel of that color. The style:

$style = array($white, $white, $white, $red, $red, $red);
imagesetstyle($image,$style);

Sets a style that is 3 pixels wide in white and 3 pixels wide in red. The style is used to fill in a draw object using the IMG_COLOR_STYLED function.

ImageLine($image, 1, 0, 96, 95, IMG_COLOR_STYLED);
This example draws 3 diagonal lines. The colors here should be 3 pixels wide and long of alternating colors.
Right click, select all, ctrl+c to copy.
Same style with a transparent back, imagerectangle, and imagesetthickness. You have to play with the rectangle numbers a bit (making it smaller than the background) to allow for the style to be on the page.
Right click, select all, ctrl+c to copy.
imagearc($image, 48, 48, 90, 90, 0, 359.9,IMG_COLOR_STYLED);
ImagefilledRectangle($image, 0, 0, 95, 96, IMG_COLOR_STYLED);
zero counts as 1, so it is really 96 pixels across and it fits.
If the style fits into the image it will create vertical stripes. The style above is 6 pixels which fits into a background of 96x96, but for some reason the rectangle must be drawn at 95,96. If it doesn't fit in the shape, it wraps around, creating different effects for different sizes.
I changed the red to black for easier viewing.
ImagefilledRectangle($image, 0, 0, 94, 96, IMG_COLOR_STYLED);
ImagefilledRectangle($image, 0, 0, 92, 96, IMG_COLOR_STYLED);
ImagefilledRectangle($image, 0, 0, 91, 96, IMG_COLOR_STYLED);
ImagefilledRectangle($image, 0, 0, 90, 96, IMG_COLOR_STYLED);
This is a good place to introduce brushes. An image can be used as a brush to paint your canvas. You can declare colors as transparent, and those that match your image brush will be transparent, allowing the background color to show through. I have not used transparency in this example, so you can see what is going on. If you look at the codes below you will see a brush is set up similar to $style by declaring your brush, using imagesetbrush($image,$brush), and then using IMG_COLOR_BRUSHED with your shape. You can also declare a style and use it with a brush by using IMG_COLOR_STYLEDBRUSHED to your shape. Finally I have also added imagesettile($image,$brush) to this page. What it does is tile across an image using IMG_COLOR_TILED. The results differ.
Image used:

BRUSHED
STYLEDBRUSHED
STYLEDBRUSHED
TILED
BRUSHED/STYLEDBRUSHED
TILED/STYLEBRUSHED

Images do not seem to work well with imagecreatetruecolor. A brush created with style and true color will work (as in the red/white examples below).

Right click, select all, ctrl+c to copy.
The BRUSHED image appears to have a motion blur effect, with the outline color of the image being the color of the motion. The STYLEDBRUSHED shows multiple images depending of the space provided by your $style (tries to fit). The TILED just tiles across.
You can create brushes out of styles. For this example, the diagonal red/white line in the first example was made into a smaller brush, and used to Brush a rectangle. Brushes created this way will work using IMG_COLOR_BRUSHED, however you must make the brush image background transparent or it will look like a motion blur image of the background color of the brush. imagecolortransparent($image,$color)can only be used once per image. It can be used on a page with nested images like a brush. imagecolortransparent($brush,$color)
BRUSHED
When you code a brush, you must use $brush (or whatever name) instead of $image for everything inside the brush image. It will not produce anything on your image canvas until called with IMG_COLOR_BRUSHED on your $image canvas.

Right click, select all, ctrl+c to copy.
From the script above using ellipse.
imageellipse($image, 45,45,56,56,IMG_COLOR_BRUSHED);
Here is an tree that uses a set style with transparent lines (in a loop), a brush with a red ball image, and a styledbrush with a style image ellipse brush. Seems you can overlap an IMG_COLOR_BRUSH with an IMG_COLOR_STYLEDBRUSHED and it will still follow the dash pattern style line underneath it all. Zip Tree File