1

I am trying to make a generator to output user data from my gaming website and I've never really looked into the conversion to images in PHP, however I've managed to get the basics of it working now from other questions on this site and elsewhere, anyway I was wondering whether it is possible to make my PHP file that generates the image, parse HTML tags in its' output? Here is my script:

<?php
$username = $_GET['username'];
$guild = $_GET['guild'];
$create = "Username: " . $username . " Guild: " . $guild . "";

$im = imagecreate(300, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 5, 0, 0, $create, $textcolor);
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

In my $create variable, I wish to use HTML tags but they aren't parsed as html and it outputs the tags in plain text.

3
  • Now, after anwserwing, I'm not sure what you want to achieve... can you be more clear? Commented Feb 22, 2013 at 16:17
  • are you asking about making an html page to show the images? Commented Feb 22, 2013 at 16:18
  • Okay so you want to use HTML to give structure to the image text? Your browser parses HTML, php does nothing with it. You'll have to use stuff like \n in your string. Commented Feb 22, 2013 at 16:19

2 Answers 2

1

Sorry, but PHP can't parse HTML before rendering it on an image. However, it does include various functions to change fonts and apply filters to the text. See http://php.net/manual/en/ref.image.php.

Is there a specific reason you need the information to be output as an image? Why not simply output the information using HTML?

Sign up to request clarification or add additional context in comments.

2 Comments

I wish to have the information output as an image so users can have it as a signature for forums etc, I was wanting to style it using HTML however, so I can give it a background image and icons. Can't find many resources for signature generators that appealed to me in a sense that they aren't for the same use as mine.
Again, you can't style HTML embedded in an image. However, you can change the text size, font, and color using PHP functions. You don't have to start with a blank canvas, either - you can overlay the dynamic text on an existing image. Here's a tutorial you may find helpful: terriswallow.com/weblog/2007/writing-text-to-images-with-php
1

Your browser parses HTML, php does nothing with it. You'll have to use stuff like \n in your string.

3 Comments

How would I do this, exactly for certain tags? I've never had to use anything like that to parse things before other than using the mail() function, however that was taken from online resources anyway.
Well let's say you want Guild to show up on a new line, you'd write $ceate = "Username: ". $username ."\nGuild". $guild;
I just tried that and it has some sort of weird symbol displayed there now that looks like a small "V" over a "T". This is really bugging me now, I've tried quite a few different things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.