### Draw Circles and Arcs

The function imagearc($image,$cx, $cy,$width, $height,$start, $end,$color) can draw circular arcs using $cx and $cy as its center. The $width and $height parameters determine the size of the arc on different axes. The $start and $end parameters specify the starting and ending angle of the arc in degrees. If you want to draw complete arcs from 0 to 360 degrees, you can use the alternative imageellipse($image,$cx, $cy,$width, $height,$color) function.

### Drawing Filled Shapes

Every drawing function also has a filled color version which fills that particular figure with a given color. For example, imagefilledrectangle() will fill the drawn rectangle with the given color.

One very useful GD function is imagesetbrush($image,$brush). The $brush parameter in this function is just another image resource which can be used to draw lines. For instance, you could use a transparent vector drawing of a flower as a brush to add nice flower patterns to your image. The code snippet given below was written to use the image of a cloud as a brush when drawing a point. This adds a single cloud in our sky. I found this cloud image on Pixabay and scaled it down to an appropriate size for our project. The complete code for the hut image is given below. We have simply added two versions of each figure, one to draw the outline and the other to fill in the color. This is the final result of the PHP GD code above. ## Rendering Text on Images PHP GD comes with four different functions to let you render either multiple characters or only one character in a horizontal or vertical direction. These functions are imagechar(), imagecharup(), imagestring(), and imagestringup(). All of them accept the same six parameters, so we will just discuss the imagechar() function here. The $font parameter imagechar($image,$font, $x,$y, $string,$color) function is simply the size of the rendered text. It only accepts integer values from 1 to 5. The $string parameter is the text that you want to render. If you pass a multi-character string to the char functions, only the first character will be rendered on the image. The imagecharup() and imagestringup() functions will render the text vertically from bottom to top. When it comes to rendering text, the four functions we discussed above are very limited. You will find that even the largest font size value is too small for normal usage. Also, the text can only be written horizontally and vertically. Luckily, GD also has a imagettftext($image, $size,$angle, $x,$y, $color,$fontfile, $text) function which can render the text in any font you want. The $fontfile parameter is used to specify the path to the TrueType font you want to use to display the text. The $x and $y parameters determine the starting position of the rendered text.

The following example uses all these functions to create some nice text effects.

As you can see, we have rendered the same text with the same font in slightly different positions to create some effects like basic text shadow. The important thing to keep in mind is that the text rendered by any text function will completely hide the text below it in case of overlap. Here is the final image obtained after running the above code.

## Final Thoughts

The aim of this tutorial was to get you acquainted with different GD functions to draw basic shapes from scratch in PHP. With the help of a little maths, you will be able to use these functions to create more complicated shapes like regular polygons, rounded rectangles, etc.

PHP GD also has a couple of very useful functions for rendering text on an image. The use of a nice font will make sure that the rendered text does not look weird when placed on regular images loaded from different file paths.

Did you create any more fancy text effects in PHP? Please share them with us in the comments.