PHP | imagecharup() Function

The imagecharup() function is an inbuilt function in PHP which is used to draw a character vertically. This function draws the first character of a string in the image identified by the image with its x and y-axis. The coordinate of the top-left corner is (0, 0).

Syntax:

bool imagecharup( $image, $font, $x, $y, $c, $color )

Parameters: This function accepts six parameters as mentioned above and described below:

  • $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
  • $font: This parameter is used to set font size of character. Its value can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding. The higher numbers represents the larger fonts and small number represent small font.
  • $x: This parameter is used to set x-coordinate to print character in image.
  • $y: This parameter is used to set y-coordinate to print character in image.
  • $c: The character which is printed.
  • $color: It sets the color. A color identifier created by imagecolorallocate() function.

Return Value: This function returns true on success or false on failure.

Below programs illustrate the imagecharup() function in PHP.



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Creates the image size
$image = imagecreate(400, 300);
  
$string = 'GeeksForGeeks';
  
// Set background color
$bg = imagecolorallocate($image, 0, 153, 0);
  
// Set character color
$white = imagecolorallocate($image, 255, 255, 255);
  
// prints a white G character
imagecharup($image, 5, 190, 150, $string, $white);
  
header('Content-type: image/png');
imagepng($image);
  
?>

chevron_right


Output:
image

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create image size
$image = imagecreate(400, 300);
  
$string = 'GeeksforGeeks';
  
// Find string length
$len = strlen($string);
  
// Set background color
$bg = imagecolorallocate($image, 0, 153, 0);
  
// Set character color
$white = imagecolorallocate($image, 255, 255, 255);
  
// Use loop to print string
for($i = 0; $i < $len; $i++)
  
    // Prints a white character $len times
    imagecharup($image, 6, 190, 230 - 10 * $i, $string[$i], $white);
  
header('Content-type: image/png');
imagepng($image);
  
?>

chevron_right


Output:
image

Related Articles:

Reference: http://php.net/manual/en/function.imagecharup.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.