Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD library, vertical text question 1

Status
Not open for further replies.

kaptlid

Technical User
Nov 26, 2006
86
0
0
US
$font = "arial.ttf";
imagettftext($image, 16, 90, 590, 350, $textColor, $font, 'Thank You');

Is there anyway to simulate the photoshop vertical text tool? So each letter individually rotates 90 degrees. i.e.

T
h
a
n
k

Y
o
u

If no do I have to get a vertical true type file for arial or verdana?
 
I was hoping to pull this off with a few lines of code not a function that does it by individual character. I was looking at that function before and wondering how fast it will process on at least 50 words of about 4-10 characters each. I'll test out manual's comments example....
I guess gd doesn't have a builtin function to flip over each character of a word. :(
And the CSS 3 tags aren't cross browser compatible. grrr......

Thanks for your help.
 
gd CAN flip characters. but you are not asking them to be flipped but rearranged to be stacked vertically rather than aligned horizontally. That is not flipping at all, but separating each letter into a paragraph.

all the function does is calculate the y-axis difference between paragraphs. it will be very fast.

if you want something to flip characters, then let us know. this can be done in one line.

i have slightly adapted and cleaned the function for a single line of text to be stacked vertically. here it is

Code:
stacktext("My name is Justin");
function stackText($text){
	$text = str_replace("\r\n", "\n" ,$text);
	$text = str_replace("\r", "\n", $text);
	$text = str_replace("\n", " ", $text);
	
	//create the image canvas (adapted from manual)
	// Set font size 
    $fontSize = 4; 

  	$lineHeight = imagefontheight($fontSize);
    $img = imagecreate(imagefontwidth($fontSize) * 3,$lineHeight * strlen($text));  
    $bg    = imagecolorallocate($img, 255, 250, 250); // off-white background 
    $colour = imagecolorallocate($img, 49, 79, 79); //dark slate colour for font 

    for($i=0;$i<strlen($text);$i++){
    	 imagechar($img, $fontSize, imagefontwidth($fontSize), $lineHeight * $i, $text[$i], $colour);
    }
	//output the image
	header("Content-type: image/png");
	imagepng($img);
	imagedestroy($img);
}
 
As I re-read your original post you say

so each letter individually rotates 90 degrees

and then you proceed to post an example where none of the letters have rotated 90 degrees. so I am actually confused as to what you wanted.

if you want a proper vertical text tool, so that each letter is rotated 90 degrees AND the canvas is vertically oriented you could

1. create a canvas and then use image_string to plot onto the canvas. then rotate it through 90 degrees.
2. create the vertical canvas and use imagestringup() to plot the string. if you want the string to be downward, just rotate the resultant canvas by 180 degrees.

this is a good example where you must be very precise in your question in order to get an on-point response.
 
Thank you so much for all your help. I was tired when I wrote the question. You answered my question. I just need the text to stack vertically that's all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top