imagechar 


gd apg

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.



  1 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(8080);

$red imagecolorallocate($img0125500);

$white imagecolorallocate($img01255255255);

$blue imagecolorallocate($img0100255);

$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.gif

GIF 006 01.gif apr

Note 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.


  2 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(8080);

$yellow imagecolorallocate($img022552550);

$blue imagecolorallocate($img0200255);

$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.jpg

JPEG 005 02.jpg apr

Note 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.


  3 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(8080);

$green imagecolorallocate($img0302550);

$white imagecolorallocate($img03255255255);

$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.png

PNG 011 03.png apr

Note 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.


  4 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(8080);

$cyan imagecolorallocate($img040255255);

$gdf_font_name04 "gdf/04b.gdf";  

$gdf_fnt04 imageloadfont($gdf_font_name04);

$blue imagecolorallocate($img0400255);

$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.jpg

JPEG 006 04.jpg apr

Note 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.