Another GD Question.

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
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Another GD Question.

Post by dcahrakos »

Well, right now, I can get text into a generated image, and everything, but say I wanted to do this:


http://dcah.z27.net/board/txt.php?txt=Need to have a line break<br>here

is there a way I can make it so, wherever I have <br> or even \n or anything really, be replaced with an actual line break? ive tried eregi_replace, explode, etc...but I can figure it out.
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

I haven't tested this but I assume all you would need is a

Code: Select all

urlencode($_GET['string']);
This will lend proper syntax to your url ie http://dcah.z27.net/board/txt.php?txt=N ... line+break

Edit:
My bad you aren't looking for spaces, though you may need that as well. For line breaks I'm not sure but I would try to code that into your GD script, pass it some type of indicator like if you want to use <br /> just have your GD script look through the string for <br />'s as an explode point. With the array that it generates you can run the script multiple times for each line.
Last edited by dyonak on Mon Nov 21, 2005 9:46 am, edited 1 time in total.
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Post by dcahrakos »

nope...that just messes everything up, and makes certain characters turn into stuff like %20%13 etc etc...and it changes <br> into %3Cbr%3E so thats not what im looking for.

im not sure if you know what I was saying though, basically, the script outputs an image with the text based on the string variable, and doing that, line breaks dont work, so I want it so I can do the following

something<br>
then after the br it goes on another line.
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

Sorry for the misread there. For line breaks I'm not sure but I would try to code that into your GD script, pass it some type of indicator like if you want to use <br /> just have your GD script look through the string for <br />'s as an explode point. With the array that it generates you can run the script multiple times for each line.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

In a word, no.

In a long, probably hair pulling function, yes.

Line breaks are not "possible" in the method in what you ask, each line must be added with imagettftext() or similar function.

So something like:

Code: Select all

<?php

$lines = explode("\n", $_GET['text']);

foreach ($lines as $line => $val) {
    imagettftext($image, $size, $angle, $x, (($y + $size) * ($line + 1)), $colour, $fontfile, $val);
}

?>
untested™
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Post by dcahrakos »

hmmm...thought it would have been a little easier then that, but ill try that out in a bit, thanks.
Post Reply