Complex code can't figure out

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Complex code can't figure out

Post by wiseguy12851 »

I am having great difficulty with this code which involves taking in a string of any length and creating an image with a certain width and height and printing the text onto the image having the text wrap through the lines until it reaches the final end of the image at the very bottom right corner, The final result is the text overlaying the image completely fitting in the image top - bottom, left - right with no added spaces etc...)

this may sound odd but has an extremely useful purpose, I have completed the idea with the problem that it mis calculates the width and height, the idea is to have a perfect box but after hundreds of tries it's either too large or too small

I need fast help

Code: Select all

$data = $_REQUEST['plaindata']; // Get Text
 
$dataLen = strlen($data); // Get the length of the data
$ii = 1; // Start the incrementer at 1
$dtSt = 0; // Start the string at character 0
 
$dataLen = sprintf("%u.0",$dataLen); // Take out all decimal points
$dataLen = $dataLen + 1;// padd an extra row and column
 
$image = imagecreatetruecolor($dataLen * 0.1256,$dataLen * 0.1256); // Create the image based on the column and row sizes at a percentage of 12.56
$BGC = imagecolorallocate($image,"0","0","0"); // Prepare Background color black
imagefill($image,"0","0",$BGC); // Fill image black
$stPX = "0"; // Assign the start pixel cursor position
 
<< do a loop writing each one and then output image to browser >>
pastcow
Forum Newbie
Posts: 5
Joined: Sun Oct 04, 2009 3:35 am
Location: Uk/Australia

Re: Complex code can't figure out

Post by pastcow »

Are you using a fixed width font? I've had a lot of problems with GD and trying to estimate font widths using its native functions.
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Re: Complex code can't figure out

Post by wiseguy12851 »

I'm going to say no to the last reply and let's just focus on the problem with width and height calculation error not on possible bugs, glitches, or etc such as gd functions.
Post Reply