Saturday, December 28, 2024
Google search engine
HomeLanguagesPHP | imagestring() Function

PHP | imagestring() Function

The imagestring() function is an inbuilt function in PHP which is used to draw the string horizontally. This function draws the string at given position.

Syntax:

bool imagestring( $image, $font, $x, $y, $string, $color )

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

  • $image: The imagecreatetruecolor() function is used to create a blank image in a given size.
  • $font: This parameter is used to set the font size. Inbuilt font in latin2 encoding can be 1, 2, 3, 4, 5 or other font identifiers registered with imageloadfont() function.
  • $x: This parameter is used to hold the x-coordinate of the upper left corner.
  • $y: This parameter is used to hold the y-coordinate of the upper left corner.
  • $string: This parameter is used to hold the string to be written.
  • $color: This parameter is used to hold the color of image.

Return Value: This function returns TRUE on success or FALSE on failure.

Below programs illustrate the imagestring() function in PHP.
Program 1:




<?php
   
// Create the size of image or blank image
$image = imagecreate(500, 300);
   
// Set the background color of image
$background_color = imagecolorallocate($image, 0, 153, 0);
   
// Set the text color of image
$text_color = imagecolorallocate($image, 255, 255, 255);
   
// Function to create image which contains string.
imagestring($image, 5, 180, 100,  "neveropen", $text_color);
imagestring($image, 3, 160, 120,  "A computer science portal", $text_color);
   
header("Content-Type: image/png");
   
imagepng($image);
imagedestroy($image);
?>


Output:
create image function

Program 2:




<?php
  
// Create the size of image or blank image
$image = imagecreate(500, 300);
  
// Set the background color of image
$background_color = imagecolorallocate($image, 255, 255, 255);
  
// Set the text color of image
$text_color = imagecolorallocate($image, 0, 153, 0);
  
// Function to create image which contains string.
imagestring($image, 5, 50, 100, 
     "neveropen: A computer science portal", $text_color);
  
header("Content-Type: image/png");
  
imagepng($image);
imagedestroy($image);
?>


Output:
imagestring function

Related Articles:

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

RELATED ARTICLES

Most Popular

Recent Comments