The imagechar() function draws a character horizontally.
Syntax
bool imagechar( img, font, x, y, ch, color )
Parameters
img: Creating an image with imagecreatetruecolor().
font: Set font size
x: x-coordinate
y: y-coordinate
c: The character to draw.
color: A color identifier created with imagecolorallocate().
Return
The imagechar() function returns TRUE on success or FALSE on failure.
Example
The following is an example:
<?php $img = imagecreate(400, 300); $str = 'Demo'; $bgcolor = imagecolorallocate($img, 30, 80, 70); $textcolor = imagecolorallocate($img, 255, 255, 255); imagechar($img, 80, 100, 90, $str, $textcolor); header('Content-type: image/png'); imagepng($img); ?>
Output
The following is the output:
Example
Let us see another example wherein we are drawing a character with different coordinates and height/ width as shown in the above example:
<?php $img = imagecreate(350, 270); $str = 'Example'; $bgcolor = imagecolorallocate($img, 70, 100, 130); $textcolor = imagecolorallocate($img, 200, 195, 210); imagechar($img, 100, 50, 70, $str, $textcolor); header('Content-type: image/png'); imagepng($img); ?>
Output
The following is the output: