What is the best way to vertically insert text into an image in PHP?

When inserting text vertically into an image in PHP, one approach is to use the GD library functions to rotate the text before placing it on the image. This can be achieved by creating a new image with the rotated text, then copying it onto the original image at the desired position.

<?php
// Load the image
$image = imagecreatefromjpeg('image.jpg');

// Set the text color and font
$textColor = imagecolorallocate($image, 255, 255, 255);
$font = 'arial.ttf';

// Rotate the text
$text = "Vertical Text";
$angle = 90;
imagettftext($image, 20, $angle, 50, 50, $textColor, $font, $text);

// Output the image
header('Content-Type: image/jpeg');
imagejpeg($image);

// Free up memory
imagedestroy($image);
?>