suzzane2020 Posted February 29, 2008 Share Posted February 29, 2008 Hi friends, I had a doubt regarding the gd library functions in php. This is what iam trying to do: I need to read contents from a html file and convert that to an image uding the gd functions. I can get the code to work using simple text(without html tags) but not without them. How do I convert the contents of the file which has html tags to an image. This is the code i have been using: <?php header ("Content-type: image/png"); $handle = ImageCreate (400, 400) or die ("Cannot Create image"); $bg_color = ImageColorAllocate ($handle, 255, 0, 0); $txt_color = ImageColorAllocate ($handle, 0, 0, 0); ImageString ($handle, 5, 5, 18, "<b>hello</b>", $txt_color); ImagePng ($handle); ?> I would really appreciate it if someone could help. Thank You Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 29, 2008 Share Posted February 29, 2008 Your code seems to work just fine for me, unless you are actually wanting the HTML to be interpreted within your image? Are you wanting that text to be bold? If so, you'll have to build a full parser and select a bold font face for those areas where you want bold, etc. Check out the options for using TTF with this function: http://us3.php.net/imagettftext[/ur]. Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted February 29, 2008 Author Share Posted February 29, 2008 Yes, Thats exactly what i want to do. And as I would be reading the contents of a file and passing that as the string, there would a lot more tags than the bold. <html><head>....etcIs there a way to do that. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 29, 2008 Share Posted February 29, 2008 There's no easy way. You would have to build a script to interpret all of the HTML, which would then decide how to format the text on the image. If you using windows with php 5.2.2 or greater, then this might be a possible solution. Basically, it allows you to take a screenshot of a window. Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 29, 2008 Share Posted February 29, 2008 Yes, Thats exactly what i want to do. And as I would be reading the contents of a file and passing that as the string, there would a lot more tags than the bold. <html><head>....etcIs there a way to do that. Not built in, no. Keep in mind that simply calling bold on a font is actually a different font set. For instance, with Arial, you have the plain arial.ttf file for normal font face, but for bold, you actually have arialbd.ttf. For italic, there is ariali.ttf and for bold-italic, there is arialbi.ttf. You would actually have to parse out the text, choose which font will accurately represent what you are after and continue your line with the new font. Do a Google search, and maybe there are some classes or tools out there that may help you along to getting where you want to be. Sounds like a very major undertaking to me, though. Good luck with it! Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted February 29, 2008 Author Share Posted February 29, 2008 ok. Will try searching gogle. Hope to find a solution. Thank you guys!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.