Vertical text in an image

By | February 7, 2011
Selec All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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