Open In App

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:

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



Below programs illustrate the imagecharup() function in PHP.

Program 1:




<?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);
  
?>

Output:

Program 2:




<?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);
  
?>

Output:

Related Articles:

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


Article Tags :