How to draw a string vertically using imagestringup() function in PHP?

imagestringup() is an inbuilt function in PHP that is used to draw an image vertically.


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


imagestring() accepts six parameters: $image, $font, $x, $y, $string, and $color.

  • $image − The $image parameter uses imagecreatetruecolor() function to create a blank image of given size.

  • $font − The $font parameter is used to set the font-size values from 1, 2, 3, 4, and 5 for inbuilt fonts or other font identifiers registered with imageloadfont() function.

  • $x − Holds the position of the font in the horizontal X-axis, upper leftmost corner.

  • $y − Holds the position of the font in the vertical Y-axis, topmost corner.

  • $string − The $string parameter holds the string to be written.

  • $color − This parameter holds the color of the image.

Return Values

imagestring() returns True on success and False on failure.


   // Create a 250*190 image using imagecreatetruecolor() function
   $img = imagecreatetruecolor(700, 300);

   // Set the background color of the image
   $bgcolor = imagecolorallocate($img, 122, 122, 122);

   // Fill background with above-selected color
   imagefill($img, 0, 0, $bgcolor);

   // Write the white color text
   $textcolor = imagecolorallocate($img, 255, 255, 255);
   imagestringup($img, 6, 130, 150, 'Hello World', $textcolor);

   // Output the picture to the browser
   header('Content-type: image/png');


Updated on: 09-Aug-2021


Kickstart Your Career

Get certified by completing the course

Get Started