imagechar DRAW a single character horizontally in an image.
This function considers upper-left at $x = 0, $y = 0.
1 ≤ $font ≤ 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont.
This function returns TRUE on success or FALSE on failure.
<?php
bool imagechar ( GdImage $image,
GdFont|int $font,
int $x,
int $y,
string $char,
int $color )
where,
$image = The image identifier
$font = The font to be used
$x = The x-coodinate to start in the image
$y = The y-coodinate to start in the image
$char = The character to be drawn
$color = The color to be used
?>
$image
The image identifier.
$font
The font to be used.
$x
The x-coodinate to start in the image.
$y
The y-coodinate to start in the image.
$char
The character to be drawn.
$color
The color to be used to draw the character created by imagecolorallocate.
EXERCISE
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$image01 = 'gif/GIF 006 01.gif';
$f01 = 6;
$x01 = 50;
$y01 = 50;
$c01 = 'ed48';
$img01 = imagecreate(80, 80);
$red = imagecolorallocate($img01, 255, 0, 0);
$white = imagecolorallocate($img01, 255, 255, 255);
$blue = imagecolorallocate($img01, 0, 0, 255);
$bool01a = imagechar($img01, $f01, $x01, $y01, $c01, $white);
if ($bool01a == true)
{
echo '$bool01a = ' . $bool01a .
'<br><br>The character was drawn!<br><br>';
}
else
{
echo '$bool01s = ' . $bool01a .
'<br><br>The character was NOT drawn!<br><br>';
}
$bool01b = imagegif($img01, $image01);
if ($bool01b == true)
{
echo '$bool01b = ' . $bool01b .
'<br><br>The image has been created!<br><br>';
echo '<img src="' . $image01 .
'" alt="' . $image01 . '" title="' . $image01 . '">';
}
else
{
echo '$bool01b = ' . $bool01b .
'<br><br>The image was NOT created!';
}
?>
RESULT The character was drawn!
The image has been created! (gif)GIF 006 01.gifNote that the first color was used to generate the RED background color of the image.
The second color WHITE draws horizontally, only, the first letter of "ed48".
This function only draws one character no matter how long the input STRING is.
EXERCISE
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$image02 = 'jpeg/JPEG 005 02.jpg';
$f02 = 6;
$x02 = 50;
$y02 = 50;
$c02 = 'ed48';
$q01 = 90;
$img02 = imagecreate(80, 80);
$yellow = imagecolorallocate($img02, 255, 255, 0);
$blue = imagecolorallocate($img02, 0, 0, 255);
$bool02a = imagechar($img02, $f02, $x02, $y02, $c02, $blue);
if ($bool02a == true)
{
echo '$bool02a = ' . $bool02a .
'<br><br>The character was drawn!<br><br>';
}
else
{
echo '$bool02s = ' . $bool02a .
'<br><br>The character was NOT drawn!<br><br>';
}
$bool02b = imagejpeg($img02, $image02, $q01);
if ($bool02b == true)
{
echo '$bool02b = ' . $bool02b .
'<br><br>The image has been created!<br><br>';
echo '<img src="' . $image02 .
'" alt="' . $image02 . '" title="' . $image02 . '">';
}
else
{
echo '$bool02b = ' . $bool02b .
'<br><br>The image was NOT created!';
}
?>
RESULT The character was drawn!
The image has been created! (jpeg)JPEG 005 02.jpgNote that the first color was used to generate the YELLOW
The second color BLUE draws horizontally, only, the first letter of "ed48".
This function only draws one character no matter how long the input STRING is.
EXERCISE
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$image03 = 'png/PNG 011 03.png';
$f03 = 6;
$x03 = 50;
$y03 = 50;
$c03 = 'ed48';
$q03 = 9;
$f03 = 3;
// PNG_FILTER_AVG
$img03 = imagecreatetruecolor(80, 80);
$green = imagecolorallocate($img03, 0, 255, 0);
$white = imagecolorallocate($img03, 255, 255, 255);
$bool03a = imagechar($img03, $f03, $x03, $y03, $c03, $white);
if ($bool03a == true)
{
echo '$bool03a = ' . $bool03a .
'<br><br>The character was drawn!<br><br>';
}
else
{
echo '$bool03s = ' . $bool03a .
'<br><br>The character was NOT drawn!<br><br>';
}
$bool03b = imagepng($img03, $image03,
$q03, $f03);
if ($bool03b == true)
{
echo '$bool03b = ' . $bool03b .
'<br><br>The image has been created!<br><br>';
echo '<img src="' . $image03 .
'" alt="' . $image03 . '" title="' . $image03 . '">';
}
else
{
echo '$bool03b = ' . $bool03b .
'<br><br>The image was NOT created!';
}
?>
RESULT The character was drawn!
The image has been created! (png)PNG 011 03.pngNote that the imagecreatetruecolor was used to generate the BLACK background color of the image.
The second color WHITE draws horizontally, only, the first letter of "ed48".
This function only draws one character no matter how long the input STRING is.
EXERCISE
<?php
echo 'PHP VERSION: ' . PHP_VERSION . '<br><br>';
$image04 = 'jpeg/JPEG 006 04.jpg';
$x04 = 50;
$y04 = 50;
$c04 = 'ed48';
$q01 = 90;
$img04 = imagecreate(80, 80);
$cyan = imagecolorallocate($img04, 0, 255, 255);
$gdf_font_name04 = "gdf/04b.gdf";
$gdf_fnt04 = imageloadfont($gdf_font_name04);
$blue = imagecolorallocate($img04, 0, 0, 255);
$bool04a = imagechar($img04, $gdf_fnt04, $x04, $y04, $c04, $blue);
if ($bool04a == true)
{
echo '$bool04a = ' . $bool04a .
'<br><br>The character was drawn!<br><br>';
}
else
{
echo '$bool04s = ' . $bool04a .
'<br><br>The character was NOT drawn!<br><br>';
}
$bool04b = imagejpeg($img04, $image04, $q01);
if ($bool04b == true)
{
echo '$bool04b = ' . $bool04b .
'<br><br>The image has been created!<br><br>';
echo '<img src="' . $image04 . '" alt="' .
$image04 . '" title="' . $image04 . '">';
}
else
{
echo '$bool04b = ' . $bool04b .
'<br><br>The image was NOT created!';
}
?>
RESULT The character was drawn!
The image has been created! (jpeg)JPEG 006 04.jpgNote that the first color was used to generate the CYAN background color of the image.
The second color BLUE draws horizontally, only, the first letter of "ed48".
This function only draws one character no matter how long the input STRING is.