LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2009, 03:21 PM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
variable length string using GD (word wrap, carriage return, word/character count)?


here's the problem
i'm trying to take elements of an array (each element is a separate string) and trying to render the strings with imagettftext

the problem is of course gd only renders so many pixels based on the width and height of the initial image so if i try to output a string that exceeds that width it gets cut off

in theory i could use strpos to cut it pieces for output
or i could use str_word_count() to break it into words and output so many
words per line by concatinating them with a separating " "

however both options only work if the text is static and always will have the same amount of total characters and the same sized words or one iteration might look fine and another might have words chopped off in the middle

perhaps somehow a combination of both? or does gdlib have a way of emulating word wrap?
edit: p.s. i have 40 columns to play with

Last edited by frieza; 02-14-2009 at 03:23 PM.
 
Old 02-14-2009, 05:21 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Original Poster
Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
nvm i seem to have figured it out, if anyone can suggest how to improve uppon this method i would appreciate it
Code:
$pos=0;
foreach($array as $key => $value) {
if ($pos == 0) {
$linepos=180;
} else {
$linepos = $linepos + 20;
}
while (strlen($string[$key]) <=38) {
$string[$key] .=$array[$pos]." ";
$pos++;
}
imagettftext($bigger,15  , 0  , 20  , $linepos  , $grey  , "./arial.ttf"  , $string[$key]);
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to replace special character by any word in a string. mksc Linux - Newbie 1 08-21-2008 02:33 AM
find a string followed by any word character in bash bryan.out.there Programming 2 07-12-2006 06:36 AM
"enscript --word-wrap" does not wrap line of text file powah Linux - General 3 05-16-2006 09:12 PM
Microsoft Word won't word wrap Micro420 General 1 06-13-2005 04:36 PM
function won ' t return character array word Linh Programming 1 07-31-2003 06:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration