Vertical text in an image

By | February 7, 2011
<?php
header ("Content-type: image/png");

// imagecreate (x width, y width)

$text = str_replace('_', ' ', $_GET['text']);
$text = ucwords($text);

$img_handle = @imagecreatetruecolor (30, 180) or die ("Cannot Create image");
// ImageColorAllocate (image, red, green, blue)
$background_color = ImageColorAllocate($img_handle, 0, 0, 0); //to become transparent later in the script
$txt_color = ImageColorAllocate($img_handle, 255, 255, 255);

// Set transparent color to background_color
imagecolortransparent($img_handle, $background_color);

// For some reason on my server the first setting of ImageColorAllocate() didn't set the canvas to that color. This gets around it.
ImageFilledRectangle($img_handle, 0,0, 30, 220, $background_color);

//Write text vertically
ImageStringUp ($img_handle, 2, 10, 175, $text, $txt_color);

//Output image
ImagePng ($img_handle);

//Destroy image
ImageDestroy($img_handle);
?>
Category: PHP